java.sql.ResultSet is an interface for executing result sets.
Description
java.sql.ResultSet generates a data table that represents a database result set, usually by executing a statement that queries the database.
A ResultSet object maintains a cursor that points to a specific data row. The cursor is initially located before the first row. After the next method is called, the cursor is moved to the next row. If no more rows exist in the ResultSet object, false is returned. Therefore, the next method can be used in a while loop to traverse the corresponding ResultSet object.
A default ResultSet object cannot be updated and has a cursor that moves only in a forward direction. In this case, you can traverse the result set only once from the first row to the last row. However, a scrollable or updatable ResultSet object will be generated. As shown in the following example, con is a valid Connection object.
Statement st = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("SELECT a, b FROM TAB1");
// rs will be scrollable and updatable but will not show changes made by others.
The ResultSet interface provides getter methods such as getBoolean and getLong that can be used to retrieve column values from the current row. Values can be retrieved by using column indexes or column names. We recommend that you use column indexes. Column indexes can be used to retrieve values in a more efficient manner than column names. Column indexes are numbered starting from 1. To achieve maximum portability, the result set columns in each row must be read from left to right, and each column must be read only once.
When the JDBC driver calls a getter method, the JDBC driver attempts to convert the underlying data into the Java type specified in the getter method and returns valid Java values.
Column names used as the input of getter methods are case-insensitive. If a getter method is called by using column names and several columns have the same name, the value of the first matching column is returned. If column names are used in the SQL statement that generated the result set, you can use the column name option. For columns that are not explicitly named in the query, we recommend that you use column numbers. If column names are used, the developer can use the AS clause to ensure that each name is referenced by only one column.
Methods
| Method | Return type | Supported in Oracle mode? | Supported in MySQL mode? |
|---|---|---|---|
| getString(int parameterIndex) | String | Yes | Yes |
| getString(String parameterName) | String | Yes | Yes |
| getInt(int parameterIndex) | int | Yes | Yes |
| getInt(String parameterName) | int | Yes | Yes |
| getLong(int parameterIndex) | long | Yes | Yes |
| getLong(String parameterName) | long | Yes | Yes |
| getFloat(int parameterIndex) | float | Yes | Yes |
| getFloat(String parameterName) | float | Yes | Yes |
| getDouble(int parameterIndex) | double | Yes | Yes |
| getDouble(String parameterName) | double | Yes | Yes |
| getBigDecimal(int parameterIndex) | BigDecimal | Yes | Yes |
| getBigDecimal(String parameterName) | BigDecimal | Yes | Yes |
| getBytes(int parameterIndex) | byte[] | Yes | Yes |
| getBytes(String parameterName) | byte[] | Yes | Yes |
| getDate(int parameterIndex) | Date | Yes | Yes |
| getDate(String parameterName) | Date | Yes | Yes |
| getTime(int parameterIndex) | Time | Yes | Yes |
| getTime(String parameterName) | Time | Yes | Yes |
| getTimestamp(int parameterIndex) | Timestamp | Yes | Yes |
| getTimestamp(String parameterName) | Timestamp | Yes | Yes |
| getBlob(int parameterIndex) | Blob | Yes | Yes |
| getBlob(String parameterName) | Blob | Yes | Yes |
| getClob(int parameterIndex) | Clob | Yes | Yes |
| getClob(String parameterName) | Clob | Yes | Yes |
| getMetaData() | ResultSetMetaData | Yes | Yes |
| getRowId(int columnIndex) | void | No | No |
| getRowId(String columnLabel) | RowId | No | No |
| updateRowId(int columnIndex,RowId x) | void | No | No |
| updateRowId(String columnLabel,RowId x) | void | No | No |
| getHoldability() | void | Yes | Yes |
| isClosed() | Boolean | Yes | Yes |
| updateNString(int columnIndex,String nString) | void | Yes | Yes |
| updateNString(String columnLabel,String nString) | void | Yes | Yes |
| updateNClob(int columnIndex,NClob nClob) | void | Yes | Yes |
| updateNClob(String columnLabel,NClob nClob) | void | Yes | Yes |
| getNClob(int columnIndex) | NClob | Yes | Yes |
| getNClob(String columnLabel) | NClob | Yes | Yes |
| getSQLXML(int columnIndex) | SQLXML | No | No |
| getSQLXML(String columnLabel) | SQLXML | No | No |
| updateSQLXML(int columnIndex,SQLXML xmlObject) | void | No | No |
| updateSQLXML(String columnLabel,SQLXML xmlObject) | void | No | No |
| getNString(int columnIndex) | String | Yes | Yes |
| getNString(String columnLabel) | String | Yes | Yes |
| getNCharacterStream(int columnIndex) | Reader | Yes | Yes |
| getNCharacterStream(String columnLabel) | Reader | Yes | Yes |
| updateNCharacterStream(int columnIndex,java.io.Reader x,long length) | void | Yes | Yes |
| updateNCharacterStream(String columnLabel,java.io.Reader reader, long length) | void | Yes | Yes |
| updateAsciiStream(int columnIndex,java.io.InputStream x,long length) | void | Yes | Yes |
| updateAsciiStream(String columnLabel,java.io.InputStream x, long length) | void | Yes | Yes |
| updateBinaryStream(int columnIndex,java.io.InputStream x,long length) | void | Yes | Yes |
| updateBinaryStream(String columnLabel,java.io.InputStream x,long length) | void | Yes | Yes |
| updateCharacterStream(String columnLabel,java.io.Reader reader, long length) | void | Yes | Yes |
| updateCharacterStream(int columnIndex,java.io.Reader x, int length) | void | Yes | Yes |
| updateCharacterStream(String columnLabel,java.io.Reader reader,int length) | void | Yes | Yes |
| updateCharacterStream(int columnIndex,java.io.Reader x,long length) | void | Yes | Yes |
| updateCharacterStream(int columnIndex,java.io.Reader x) | void | Yes | Yes |
| updateCharacterStream(String columnLabel,java.io.Reader reader) | void | Yes | Yes |
| updateBlob(int columnIndex,InputStream inputStream) | void | Yes | Yes |
| updateBlob(String columnLabel,InputStream inputStream) | void | Yes | Yes |
| updateClob(int columnIndex,Reader reader) | void | Yes | Yes |
| updateClob(String columnLabel,Reader reader) | void | Yes | Yes |
| updateNClob(int columnIndex,Reader reader) | void | Yes | Yes |
| updateNClob(String columnLabel,Reader reader) | void | Yes | Yes |
| getObject(int columnIndex,Class<T> type) | <T> | Yes | Yes |
| getObject(String columnLabel,Class<T> type) | <T> | Yes | Yes |
| updateObject(int columnIndex,Object x,SQLType targetSqlType, int scaleOrLength) | void | No | No |
| updateObject(String columnLabel,Object x,SQLType targetSqlType, int scaleOrLength) | void | No | No |
| updateObject(int columnIndex,Object x,SQLType targetSqlType) | void | No | No |
| updateObject(String columnLabel,Object x,SQLType targetSqlType) | void | No | No |