【Java开源代码栏目提醒】:网学会员--在 Java开源代码编辑为广大网友搜集整理了:AgencyBean.java绩等信息,祝愿广大网友取得需要的信息,参考学习。
package agency;
import java.rmi.*;
import java.sql.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.* ;
import javax.
sql.*;
public class AgencyBean implements SessionBean
{
private DataSource dataSource;
private String name = "";
public String getAgencyName() {
return name;
}
public Collection findAllApplicants() {
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
con = dataSource.getConnection();
stmt = con.prepareStatement(
"SELECT login FROM Applicant");
rs = stmt.executeQuery();
Collection col = new TreeSet();
while (rs.next()) {
col.add(rs.getString(1));
}
return col;
}
catch (SQLException e) {
error("Error getting Applicant list",e);
}
finally {
closeConnection(con, stmt, rs);
}
return null;
}
public void createApplicant(String login, String name, String email) throws DuplicateException, CreateException{
Collection apps = findAllApplicants();
Iterator it = apps.iterator();
while (it.hasNext()) {
String s = (String)it.next();
if (s.equalsIgnoreCase(login))
throw (new DuplicateException(s+" applicant already defined"));
}
Connection con = null;
PreparedStatement stmt = null;
try {
con = dataSource.getConnection();
stmt = con.prepareStatement(
"INSERT INTO Applicant (login,name,email) VALUES (?, ?, ?)");
stmt.setString(1, login);
stmt.setString(2, name);
stmt.setString(3, email);
stmt.executeUpdate();
}
catch (SQLException e) {
error("Error creating Applicant "+login,e);
}
finally {
closeConnection(con, stmt, null);
}
}
public void deleteApplicant (String login) throws NotFoundException{
Connection con = null;
PreparedStatement stmt = null;
try {
con = dataSource.getConnection();
con.setAutoCommit(false);
stmt = con.prepareStatement(
"DELETE FROM ApplicantSkill WHERE applicant = ?");
stmt.setString(1, login);
stmt.executeUpdate();
stmt = con.prepareStatement(
"DELETE FROM Applicant WHERE login = ?");
stmt.setString(1, login);
stmt.executeUpdate();
con.commit();
}
catch (SQLException e) {
if (con != null) {
try {
con.rollback();
}
catch (SQLException ex) {}
}
error("Error deleteing Applicant "+login,e);
}
finally {
closeConnection(con, stmt, null);
}
}
public Collection findAllCustomers() {
Connection con = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
con = dataSource.getConnection();
stmt = con.prepareStatement(
"SELECT login FROM Customer");
rs = stmt.executeQuery();
Collection col = new TreeSet();
while (rs.next()) {
col.add(rs.getString(1));
}
return col;
}
catch (SQLException e) {
error("Error getting Customer list",e);
}
finally {
closeConnection(con, stmt, rs);
}
return null;
}
public void createCustomer(String login, String name, String email) throws DuplicateException, CreateException{
Collection cust = findAllCustomers();
Iterator it = cust.iterator();
while (it.hasNext()) {
String s = (String)it.next();
if (s.equalsIgnoreCase(login))
throw (new DuplicateException(s+" customer already defined"));
}
Connection con = null;
PreparedStatement stmt = null;
try {
con = dataSource.getConnection();
stmt = con.prepareStatement(
"INSERT INTO Customer (login,name,email) VALUES (?, ?, ?)");
stmt.setString(1, login);
stmt.setString(2, name);
stmt.setString(3, email);
stmt.executeUpdate();
}
catch (SQLException e) {
error("Error creating Customer "+login,e);
}
finally {
closeConnection(con, stmt, null);
}
}
public void deleteCustomer (String login) throws NotFoundException {
Connection con = null;
PreparedStatement stmt = null;
try {
con = dataSource.getConnection();
con.setAutoCommit(false);
stmt = con.prepareStatement(
"DELETE FROM InvoiceItem WHERE customer = ?");
stmt.setString(1, login);
stmt.executeUpdate();
stmt = con.prepareStatement(
"DELETE FROM Invoice WHERE customer = ?");
stmt.setString(1, login);
stmt.executeUpdate();
stmt = con.prepareStatement(
"DELETE FROM JobSkill WHERE customer = ?");
stmt.setString(1, login);
stmt.executeUpdate();
stmt = con.prepareStatement(
"DELETE FROM Job WHERE customer = ?");
stmt.setString(1, login);
stmt.executeUpdate();
stmt = con.prepareStatement(
"DELETE FROM Customer WHERE login = ?");
stmt.setString(1, login);
stmt.executeUpdate();
con.commit();
}
catch (SQLException e) {
if (con != null) {
try {
con.rollba