JDBC PS retrieving ResultSet rows

Retrieving data from ResultSet table using a PreparedStatement object.

You can then freely choose one of the
6 preparedStatement()
methods that are available to create a PreparedStatement object.

If you have any parametric placeholders for
values in your SQL statement, then it is time to
set these using the PreparedStatement
setXXX() methods.

The next step is to retrieve the ResultSet object
from the PreparedStatement object with the
executeQuery() method:

Now you can set the cursor to a row
using one of the
positioning methods in the ResultSet object.
Which methods of these to use depends on the scrolling you have selected when
you created the PreparedStatement object.

When a row in the ResultSet is accessible several ResultSet
methods can be used to retrieve column data.

Here is the most used:

Methods in ResultSet interface

Description

double getDouble(int)
double getDouble(String)

Gets a double from a column with number (1.. N) or database
table defined column name.

float getFloat(int)
float getFloat(String)

Gets a float from a column with number (1.. N) or database
table defined column name.

int getInt(int)
int getInt(String)

Gets an int from a column with number (1.. N) or database
table defined column name.

long getLong(int)
long getLong(String)

Gets a long from a column with number (1.. N) or database
table defined column name.

short getShort(int)
short getShort(String)

Gets a short from a column with number (1.. N) or database
table defined column name.

String getString(int)
String getString(String)

Gets a String from a column with number (1.. N) or database
table defined column name.

Time getTime(int)
Time getTime(String)

Gets a Time from a column with number (1.. N) or database
table defined column name.

Time getTime(int, Calendar)
Time getTime(String, Calendar)

Gets a Time from a column with number (1.. N) or database
table defined column name. For both methods Calendar object
is used in constructing the Time.

Date getDate(int)
Date getDate(String)

Gets a Date from a column with number (1.. N) or database
table defined column name.

Date getDate(int, Calendar)
Date getDate(String, Calendar)

Gets a Date from a column with number (1.. N) or database
table defined column name. For both methods Calendar object
is used in constructing the Date.

Timestamp getTimestamp(int)
Timestamp getTimestamp(String)

Gets a Timestamp from a column with number (1.. N) or database
table defined column name.