public class StudentEJB implements EntityBean {
private String studentID; //also primary key
private String firstName;
private String lastName;
private String address;
public String ejbCreate(String s, String f, String l, String
a) throws CreateException {
studentID =s;
firstName =f;
lastName = l;
address = a;
Conection con = null
PreparedStatement ps = nu;;
try {
con = getConnection();
ps = con.preparedStatement("insert into students (student_id,
"+ " first_name, lastname, address) values (?,?,?,?)");
ps.setString(1, studentID);
ps.setString(1,firstName);
ps.setString(1, lastName);
ps.SetString(1,addresss);
if(ps.executeUpdate() != 1) {
String error = "JDBC did not create any row";
log(error);
thow new CreateException(error);
}
return studentID;
} catch(SQLException sqe) { ....} finally { cleanup(con,ps);
}
}
}
|