예제 #1
0
 private void setCarDescription(PreparedStatement statement, CarDescription carDescription)
     throws SQLException {
   int i = 0;
   statement.setLong(++i, carDescription.getModel().getId());
   statement.setInt(++i, carDescription.getPrice());
   statement.setInt(++i, carDescription.getDoors());
   statement.setInt(++i, carDescription.getSeats());
   statement.setInt(++i, carDescription.getConsumption());
   statement.setBoolean(++i, carDescription.isAirCondition());
   statement.setBoolean(++i, carDescription.isAirBags());
   statement.setBoolean(++i, carDescription.isAutomatic());
   statement.setString(++i, carDescription.getDescription());
   statement.setString(++i, carDescription.getImgUrl());
 }
예제 #2
0
 @Override
 public int update(CarDescription model) throws DatabaseException {
   if (model == null) {
     throw new DatabaseException("Model is null");
   }
   int rows = 0;
   Connection connection = connectionPool.takeConnection();
   PreparedStatement statement = null;
   try {
     statement = openPrepStatement(connection, UPDATE);
     setCarDescription(statement, model);
     statement.setLong(11, model.getId());
     rows = statement.executeUpdate();
   } catch (SQLException e) {
     throw new DatabaseException("Updating car description failed", e);
   } finally {
     closeStatement(statement);
     connectionPool.releaseConnection(connection);
   }
   return rows;
 }