How to retrieve values from ResultSet?
Here is another example how to read data from a ResultSet returned by a executing an SQL query to a table in database.
The code above can be read as the following: create a connection to the database, see the getConnection() method. Create a PreparedStatement to execute a query to get some date from the BOOKS table.
After statement execution you'll have a ResultSet object, the iterate all the data in the ResultSet you need to call the next() method. When no other record to read it return false. The ResultSet object rs also provides some methods to read value of the fields, the name of the method is corresponded to the type of data stored on each field of the table.
To read data using this methods (eg. getString(), getInt(), getFloat(), etc) you can either use the column name or the column index of the field read in the statement.