Java Reference
In-Depth Information
} catch (NamingException ne) {
System.out.println("Could not obtain InitialContext");
}
}
public String ejbCreate(String id, String nLast, String nFirst, int mYear)
throws CreateException {
Connection con = null;
PreparedStatement ps = null;
try {
con = getConnection();
ps = con.prepareStatement("INSERT into member values(?, ?, ?, ?)");
ps.setString(1, id);
ps.setString(2, nLast);
ps.setString(3, nFirst);
ps.setInt(4, mYear);
if (ps.executeUpdate() != 1) {
System.out.println("Insert data failed!");
throw new CreateException("JDBC could not create a row.");
}
// assign instance attrubute values
memberId = id;
lastName = nLast;
firstName = nFirst;
membershipYear = mYear;
} catch (SQLException sqe) {
// Check if the exception was due to an existing entry in the
database.
try {
ejbFindByPrimaryKey(id);
} catch (ObjectNotFoundException e) {
System.out.println("Ambiguous SQLException: " + sqe);
throw new CreateException("Ambiguous SQLException");
}
System.out.println("A member with this ID already exists.");
throw new DuplicateKeyException("A member with this ID already
exists.");
} finally {
cleanup(con, ps);
}
return memberId;
}
public void ejbPostCreate(String name, int age) {
Search WWH ::




Custom Search