The ejbRemove( ) Method

In addition to handling their own inserts and updates, bean-managed entities must handle their own deletions. When a client application invokes the remove method on the EJB home or EJB object, that method invocation is delegated to the bean-managed entity by calling ejbRemove( ). It is the bean developer’s responsibility to implement an ejbRemove( ) method that deletes the entity’s data from the database. Here’s the ejbRemove( ) method for our bean-managed ShipBean:

public void ejbRemove( ) {
    Connection con = null;
    PreparedStatement ps = null;
    try {
        con = this.getConnection( );
        ps = con.prepareStatement("delete from Ship where id = ?");
        ps.setInt(1, id.intValue( ));
        if (ps.executeUpdate( ) != 1) {
            throw new EJBException("ejbRemove");
        }
    }
    catch (SQLException se) {
        throw new EJBException (se);
    }
    finally {
        try {
            if (ps != null) ps.close( ); 
            if (con!= null) con.close( ); 
        } catch(SQLException se) {
            se.printStackTrace( );
        }
    }
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.218.226