ResultSet resultSet = statement.executeQuery("SELECT COUNT(*) FROM table1"); if(resultSet.next()){ Integer count = (Integer)resultSet.getObject(1); System.out.println("Table1 has "+count+" records"); }
ResultSet resultSet = statement.executeQuery("SELECT name FROM table2 WHERE id=1"); if(resultSet.next()){ String name = (String)resultSet.getObject(1); System.out.println("The name of table2's record with id=1 is "+name); } Example 3: Retrieving a date value from a resultSet objectResultSet resultSet = statement.executeQuery("SELECT dob FROM table3 WHERE id=2"); if(resultSet.next()){ Date dob = (Date)resultSet.getObject(1); System.out.println("The date of birth of table3's record with id=2 is "+dob); } ``` These examples are part of the JDBC API and are included in the java.sql package library.