예제 #1
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);
      }
    }
  }