コード例 #1
0
 private void update(Company company) throws DaoException {
   PreparedStatement statement = null;
   try {
     statement = JdbcUtils.getConnection().prepareStatement(UPDATE);
     statement.setString(1, company.getName());
     statement.setLong(2, company.getId());
     statement.execute();
   } catch (SQLException e) {
     logger.warn(e.getMessage());
     throw new DaoException(e);
   } finally {
     JdbcUtils.closeStatement(statement);
   }
 }
コード例 #2
0
 private void save(Company company) throws DaoException {
   PreparedStatement statement = null;
   ResultSet resultKey = null;
   try {
     statement = JdbcUtils.getConnection().prepareStatement(SAVE, Statement.RETURN_GENERATED_KEYS);
     statement.setString(1, company.getName());
     statement.execute();
     resultKey = statement.getGeneratedKeys();
     resultKey.next();
     long id = resultKey.getLong(1);
     company.setId(id);
   } catch (SQLException e) {
     logger.warn(e.getMessage());
     throw new DaoException(e);
   } finally {
     JdbcUtils.closeResultSet(resultKey);
     JdbcUtils.closeStatement(statement);
   }
 }