Retrieving Query Results

At some point an application will want to retrieve some data from the database. The method that returns an answer set is executeQuery(). This method takes an SQL string as its argument and attempts to create a result set from the database.

ResultSet rs = null;
rs = s.executeQuery("SELECT Production_Title FROM Productions");

A result set will contain a number of rows, with each row containing the columns that are specified in the select list. A result set is very similar to an array of records. For instance, the previous example returns 10 rows, but with only one column (Production_Title) being returned from the Productions table.

To retrieve the values from the result set, a simple while loop can be created to process ...

Get Apache Derby—Off to the Races: Includes Details of IBM® Cloudscape™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.