ページの先頭行へ戻る
Interstage Application Server/Interstage Web Server J2EE ユーザーズガイド

13.6.7 ejbRemoveメソッドの記述

コンテナがデータベースからデータを削除するときに呼び出すメソッドです。

Entity Beanを呼び出すEJBアプリケーションがremoveメソッドを呼び出すと、コンテナはremoveメソッドに対応するejbRemoveメソッドを呼び出します。

記述する処理の概要

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");
  }