double age = 0;
long person_id = 0;
String name = null;
Timestamp birth_date = null;
int rows = 0;
ResultSet rslt = null;
Statement stmt = null;
try {
stmt = conn.createStatement();
rslt = stmt.executeQuery(
"select person_id, last_name||', '||first_name name, " +
"birth_date, ( months_between( sysdate, birth_date ) / 12 ) age " +
"from PERSON where last_name = 'O''Reilly' and first_name = 'Tim'");
if (rslt.next()) {
rows++;
person_id = rslt.getLong(1);
name = rslt.getString(2);
birth_date = rslt.getTimestamp(3);
age = rslt.getDouble(4);
System.out.println("person_id = " +
new Long(person_id).toString());
System.out.println("name = " + name);
System.out.println("birth_date = " +
new SimpleDateFormat("MM/dd/yyyy").format(birth_date));
System.out.println("age = " +
new DecimalFormat("##0.#").format(age));
}
rslt.close();
rslt = null;
stmt.close();
stmt = null;
}
catch (SQLException e) {
System.err.println(e.getMessage());
}
finally {
if (rslt != null)
try { rslt.close(); } catch (SQLException ignore) { }
if (stmt != null)
try { stmt.close(); } catch (SQLException ignore) { }
}