0 Replies Latest reply on Jul 16, 2003 11:41 AM by miloud

    executeUpdate returns false result

    miloud Newbie

      Hello,

      The methods executeUpdate returns sometimes false results in the ejbCreate and the ejbRemove.
      This method returns 0, but the insert is good to the base.
      The method executeUpdate return normaly 1.
      Why is the problem?

      This is the method ejbCreate :

      public RentalPK ejbCreate(BigDecimal subId, BigDecimal disId, Timestamp renDate, String renNumLettreEnvoi, String renNumLettreRetour) throws CreateException {
      super.ejbCreate(subId, disId, renDate, renNumLettreEnvoi, renNumLettreRetour);
      try {
      //First see if the object already exists
      ejbFindByPrimaryKey(new RentalPK(subId, disId));
      //If so, then we have to throw an exception
      throw new DuplicateKeyException("Primary key already exists");
      }
      catch(ObjectNotFoundException e) {
      //Otherwise we can go ahead and create it...
      }
      Connection connection = null;
      PreparedStatement statement = null;
      try {
      connection = dataSource.getConnection();
      //System.out.println("subId:"+subId+"|disId:"+disId+"|renDate:"+renDate+"|renNumLettreEnvoi"+renNumLettreEnvoi+"|renNumLettreRetour:"+renNumLettreRetour);
      statement = connection.prepareStatement("INSERT INTO \"RENTAL\" (sub_Id, dis_Id, ren_Date, ren_NumLettreEnvoi, ren_NumLettreRetour) VALUES (?, ?, ?, ?, ?)");
      statement.setBigDecimal(1, subId);
      statement.setBigDecimal(2, disId);
      statement.setTimestamp(3, renDate);
      statement.setString(4, renNumLettreEnvoi);
      statement.setString(5, renNumLettreRetour);
      if (statement.executeUpdate() != 1) {
      throw new CreateException("Error adding row");
      }
      return new RentalPK(subId, disId);
      }
      catch(SQLException e) {
      throw new EJBException("Error executing SQL INSERT INTO \"RENTAL\" (sub_Id, dis_Id, ren_Date, ren_NumLettreEnvoi, ren_NumLettreRetour) VALUES (?, ?, ?, ?, ?): " + e.toString());
      }
      finally {
      closeConnection(connection, statement);
      }
      }