object is the primary storage mechanism for the data returned by an SQL statement. Each ResultSet
object contains both data and metadata
(in the form of a ResultSetMetaData
includes useful information about results returned by the SQL command: column names, column count, row count, column length, and so on.
To access the row data stored in a ResultSet
object, an application calls one or more getter
methods. A getter
method retrieves the value in particular column of the current row. There are many different getter
methods; each method returns a value of a particular type. For example, the getString()
method returns a STRING
type; the getDate()
method returns a Date
, and the getInt()
method returns an INT
type. When an application calls a getter
method, JDBC tries to convert the value into the requested type.
keeps an internal pointer that points to the current row. When the executeQuery()
method returns a ResultSet
, the pointer is positioned before
the first row; if an application calls a getter
method before moving the pointer, the getter
method will fail. To advance to the next (or first) row, call the ResultSet
is a boolean method; it returns TRUE
if there is another row in the ResultSet
if you have moved past the last row.
After moving the pointer to the first row, the sample application uses the getString
method to retrieve the value in the first column and then prints that value. Since ListEmployees
in a loop, it processes each row in the result set. ListEmployees
exits the loop when rs.next()
moves the pointer past the last row and returns FALSE
|You must call next()
before reading any values. next()
returns true if another row is available and prepares the row for processing.