예제 #1
0
 public int update(ProductLine productLine, Connection con) throws SQLException {
   try (PreparedStatement prepareStmt = con.prepareStatement(updateProductLine)) {
     prepareStmt.setString(1, productLine.getName());
     prepareStmt.setString(2, productLine.getDescription());
     prepareStmt.setInt(3, productLine.getId());
     return prepareStmt.executeUpdate();
   }
 }
예제 #2
0
  public int save(ProductLine productLine, Connection con)
      throws ClassNotFoundException, SQLException {
    try (PreparedStatement prepStatement =
        con.prepareStatement(insertProductLine, Statement.RETURN_GENERATED_KEYS)) {
      prepStatement.setString(1, productLine.getName());
      prepStatement.setString(2, productLine.getDescription());
      if (productLine.getParent() == null) {
        prepStatement.setNull(3, Types.NULL);
      } else {
        prepStatement.setInt(3, productLine.getParent().getId());
      }
      boolean a = prepStatement.execute();

      try (ResultSet rs = prepStatement.getGeneratedKeys()) {
        rs.next();
        return rs.getInt(1);
      }
    }
  }