| Interstage Application Server J2EE ユーザーズガイド |
目次
索引
![]()
|
| 第3部 EJB編 | > 第12章 Entity Beanの実装 | > 12.6 BMPのEnterprise Beanクラスの作成 |
コンテナがデータベースからデータを削除するときに呼び出すメソッドです。
Entity Beanを呼び出すEJBアプリケーションがremoveメソッドを呼び出すと、コンテナはremoveメソッドに対応するejbRemoveメソッドを呼び出します。
ejbRemoveメソッドには、以下の処理を記述します。
ejbRemoveメソッドは以下の規約を満たしていなければなりません。
public void ejbRemove() throws javax.ejb.EJBException, javax.ejb.RemoveException
{
Connection connection = null;
PreparedStatement psDelete = null;
SampleBeanPrimaryKey pk = null;
int rows = 0;
try
{
// レコードの削除
connection = dataSource.getConnection();
psDelete = connection.prepareStatement("DELETE FROM SAMPLESCM.SAMPLETBL WHERE ID = ?");
pk = (SampleBeanPrimaryKey)context.getPrimaryKey();
psDelete.setObject(1,pk.code);
rows = psDelete.executeUpdate();
}
catch(SQLException e)
{
throw new EJBException(e.getMessage());
}
finally
{
try
{
if (psDelete != null)
psDelete.close();
if (connection != null)
connection.close();
}
catch(Exception e) {}
}
if (rows != 1)
throw new RemoveException("ejbRemove failed");
}
目次
索引
![]()
|