Ejemplo n.º 1
0
  /**
   * Queries persons older than provided age.
   *
   * @param conn JDBC connection.
   * @param minAge Minimum age.
   * @throws SQLException In case of SQL error.
   */
  private static void queryPersons(Connection conn, int minAge) throws SQLException {
    PreparedStatement stmt = conn.prepareStatement("select name, age from Person where age >= ?");

    stmt.setInt(1, minAge);

    ResultSet rs = stmt.executeQuery();

    X.println(">>> Persons older than " + minAge + ":");

    while (rs.next())
      X.println(">>>     " + rs.getString("NAME") + " (" + rs.getInt("AGE") + " years old)");
  }