Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
A ResultSet provides access to a table of data generated by executing a Statement. The table rows are retrieved in sequence. Within a row its column values can be accessed in any order.
A ResultSet maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The 'next' method moves the cursor to the next row.
The getXXX methods retrieve column values for the current row. You can retrieve values either using the index number of the column, or by using the name of the column. In general using the column index will be more efficient. Columns are numbered from 1.
For maximum portability, ResultSet columns within each row should be read in left-to-right order and each column should be read only once.
For the getXXX methods, the JDBC driver attempts to convert the underlying data to the specified Java type and returns a suitable Java value. See the JDBC specification for allowable mappings from SQL types to Java types with the ResultSet.getXXX methods.
Column names used as input to getXXX methods are case insensitive. When performing a getXXX using a column name, if several columns have the same name, then the value of the first matching column will be returned. The column name option is designed to be used when column names are used in the SQL query. For columns that are NOT explicitly named in the query, it is best to use column numbers. If column names were used there is no way for the programmer to guarantee that they actually refer to the intended columns.
A ResultSet is automatically closed by the Statement that generated it when that Statement is closed, re-executed, or is used to retrieve the next result from a sequence of multiple results.
The number, types and properties of a ResultSet's columns are provided by the ResulSetMetaData object returned by the getMetaData method.
Field Summary | |
static int | CONCUR_LOCK
|
static int | CONCUR_READ_ONLY
|
static int | CONCUR_VALUE
|
static int | CONCUR_VERSION
|
static int | FETCH_FORWARD
|
static int | FETCH_REVERSE
|
static int | FETCH_UNKNOWN
|
static int | TYPE_DYNAMIC
|
static int | TYPE_FORWARD_ONLY
|
static int | TYPE_KEYSET
|
static int | TYPE_STATIC
|
Method Summary | |
boolean | absolute(int row)
Move to an absolute row number in the result set. |
void | afterLast()
Moves to the end of the result set, just after the last row. |
void | beforeFirst()
Moves to the front of the result set, just before the first row. |
void | clearWarnings()
|
void | close()
|
void | deleteRow()
|
int | findColumn(String columnName)
|
boolean | first()
Moves to the first row in the result set. |
ArrayLocator | getArrayLocator(int i)
|
ArrayLocator | getArrayLocator(String colName)
|
InputStream | getAsciiStream(int columnIndex)
|
InputStream | getAsciiStream(String columnName)
|
BigDecimal | getBigDecimal(int columnIndex,
int scale)
|
BigDecimal | getBigDecimal(String columnName,
int scale)
|
BigDecimal | getBigDecimal(int columnIndex)
|
BigDecimal | getBigDecimal(String columnName)
|
InputStream | getBinaryStream(int columnIndex)
|
InputStream | getBinaryStream(String columnName)
|
BlobLocator | GetBlobLocator(int i)
|
BlobLocator | GetBlobLocator(String colName)
|
boolean | getBoolean(int columnIndex)
|
boolean | getBoolean(String columnName)
|
byte | getByte(int columnIndex)
|
byte | getByte(String columnName)
|
byte[] | getBytes(int columnIndex)
|
byte[] | getBytes(String columnName)
|
Reader | getCharacterStream(int columnIndex)
Get the value of a column in the current row as a java.io.Reader. |
Reader | getCharacterStream(String columnName)
Get the value of a column in the current row as a java.io.Reader. |
ClobLocator | getClobLocator(int i)
|
ClobLocator | getClobLocator(String colName)
|
int | getConcurrency()
|
String | getCursorName()
|
Date | getDate(int columnIndex)
|
Date | getDate(String columnName)
|
double | getDouble(int columnIndex)
|
double | getDouble(String columnName)
|
int | getFetchDirection()
|
int | getFetchSize()
|
float | getFloat(int columnIndex)
|
float | getFloat(String columnName)
|
int | getInt(int columnIndex)
|
int | getInt(String columnName)
|
int | getKeysetSize()
|
long | getLong(int columnIndex)
|
long | getLong(String columnName)
|
ResultSetMetaData | getMetaData()
|
Object | getObject(int columnIndex)
Get the value of a column in the current row as a Java object. |
Object | getObject(String columnName)
Get the value of a column in the current row as a Java object. |
Object | getObject(int i,
Map map)
|
Object | getObject(String colName,
Map map)
|
Ref | getRef(int i)
|
Ref | getRef(String colName)
|
int | getRow()
Determine the current row number. |
short | getShort(int columnIndex)
|
short | getShort(String columnName)
|
Statement | getStatement()
|
String | getString(int columnIndex)
|
String | getString(String columnName)
|
StructLocator | getStructLocator(int i)
|
StructLocator | getStructLocator(String colName)
|
Time | getTime(int columnIndex)
|
Time | getTime(String columnName)
|
Timestamp | getTimestamp(int columnIndex)
|
Timestamp | getTimestamp(String columnName)
|
int | getType()
|
InputStream | getUnicodeStream(int columnIndex)
|
InputStream | getUnicodeStream(String columnName)
|
SQLWarning | getWarnings()
The first warning reported by calls on this ResultSet is returned. |
void | insertRow()
|
boolean | isAfterLast()
Determine if the cursor is after the last row in the result set. |
boolean | isBeforeFirst()
Determine if the cursor is before the first row in the result set. |
boolean | isFirst()
Determine if the cursor is on the first row of the result set. |
boolean | isLast()
Determine if the cursor is on the last row of the result set. |
boolean | last()
Moves to the last row in the result set. |
void | moveToCurrentRow()
|
void | moveToInsertRow()
|
boolean | next()
|
boolean | previous()
Moves to the previous row in the result set. |
void | refreshRow()
|
boolean | relative(int rows)
Moves a relative number of rows, either positive or negative. |
boolean | rowDeleted()
|
boolean | rowInserted()
|
boolean | rowUpdated()
|
void | setFetchDirection(int direction)
|
void | setFetchSize(int rows)
|
void | setKeysetSize(int keys)
|
void | updateAsciiStream(int columnIndex,
InputStream x,
int length)
|
void | updateAsciiStream(String columnName,
InputStream x,
int length)
|
void | updateBigDecimal(int columnIndex,
BigDecimal x)
|
void | updateBigDecimal(String columnName,
BigDecimal x)
|
void | updateBinaryStream(int columnIndex,
InputStream x,
int length)
|
void | updateBinaryStream(String columnName,
InputStream x,
int length)
|
void | updateBoolean(int columnIndex,
boolean x)
|
void | updateBoolean(String columnName,
boolean x)
|
void | updateByte(int columnIndex,
byte x)
|
void | updateByte(String columnName,
byte x)
|
void | updateBytes(int columnIndex,
byte[] x)
|
void | updateBytes(String columnName,
byte[] x)
|
void | updateCharacterStream(int columnIndex,
Reader reader,
int length)
|
void | updateCharacterStream(String columnName,
Reader reader,
int length)
|
void | updateDate(int columnIndex,
Date x)
|
void | updateDate(String columnName,
Date x)
|
void | updateDouble(int columnIndex,
double x)
|
void | updateDouble(String columnName,
double x)
|
void | updateFloat(int columnIndex,
float x)
|
void | updateFloat(String columnName,
float x)
|
void | updateInt(int columnIndex,
int x)
|
void | updateInt(String columnName,
int x)
|
void | updateLong(int columnIndex,
long x)
|
void | updateLong(String columnName,
long x)
|
void | updateNull(int columnIndex)
|
void | updateNull(String columnName)
|
void | updateObject(int columnIndex,
Object x,
int scale)
|
void | updateObject(int columnIndex,
Object x)
|
void | updateObject(String columnName,
Object x,
int scale)
|
void | updateObject(String columnName,
Object x)
|
void | updateRow()
|
void | updateShort(int columnIndex,
short x)
|
void | updateShort(String columnName,
short x)
|
void | updateString(int columnIndex,
String x)
|
void | updateString(String columnName,
String x)
|
void | updateTime(int columnIndex,
Time x)
|
void | updateTime(String columnName,
Time x)
|
void | updateTimestamp(int columnIndex,
Timestamp x)
|
void | updateTimestamp(String columnName,
Timestamp x)
|
boolean | wasNull()
|
Field Detail |
public static final int FETCH_FORWARD
public static final int FETCH_REVERSE
public static final int FETCH_UNKNOWN
public static final int TYPE_FORWARD_ONLY
public static final int TYPE_STATIC
public static final int TYPE_KEYSET
public static final int TYPE_DYNAMIC
public static final int CONCUR_READ_ONLY
public static final int CONCUR_LOCK
public static final int CONCUR_VERSION
public static final int CONCUR_VALUE
Method Detail |
public boolean next() throws SQLException
If an input stream from the previous row is open, it is implicitly closed. The ResultSet's warning chain is cleared when a new row is read.
public void close() throws SQLException
Note: A ResultSet is automatically closed by the Statement that generated it when that Statement is closed, re-executed, or is used to retrieve the next result from a sequence of multiple results. A ResultSet is also automatically closed when it is garbage collected.
public boolean wasNull() throws SQLException
public String getString(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public boolean getBoolean(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public byte getByte(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public short getShort(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public int getInt(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public long getLong(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public float getFloat(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public double getDouble(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
scale
- the number of digits to the right of the decimal
public byte[] getBytes(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public Date getDate(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public Time getTime(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public Timestamp getTimestamp(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public InputStream getAsciiStream(int columnIndex) throws SQLException
Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a get method implicitly closes the stream. . Also, a stream may return 0 for available() whether there is data available or not.
columnIndex
- the first column is 1, the second is 2, ...
public InputStream getUnicodeStream(int columnIndex) throws SQLException
Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a get method implicitly closes the stream. . Also, a stream may return 0 for available() whether there is data available or not.
columnIndex
- the first column is 1, the second is 2, ...
public InputStream getBinaryStream(int columnIndex) throws SQLException
Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a get method implicitly closes the stream. Also, a stream may return 0 for available() whether there is data available or not.
columnIndex
- the first column is 1, the second is 2, ...
public String getString(String columnName) throws SQLException
columnName
- is the SQL name of the column
public boolean getBoolean(String columnName) throws SQLException
columnName
- is the SQL name of the column
public byte getByte(String columnName) throws SQLException
columnName
- is the SQL name of the column
public short getShort(String columnName) throws SQLException
columnName
- is the SQL name of the column
public int getInt(String columnName) throws SQLException
columnName
- is the SQL name of the column
public long getLong(String columnName) throws SQLException
columnName
- is the SQL name of the column
public float getFloat(String columnName) throws SQLException
columnName
- is the SQL name of the column
public double getDouble(String columnName) throws SQLException
columnName
- is the SQL name of the column
public BigDecimal getBigDecimal(String columnName, int scale) throws SQLException
columnName
- is the SQL name of the column
scale
- the number of digits to the right of the decimal
public byte[] getBytes(String columnName) throws SQLException
columnName
- is the SQL name of the column
public Date getDate(String columnName) throws SQLException
columnName
- is the SQL name of the column
public Time getTime(String columnName) throws SQLException
columnName
- is the SQL name of the column
public Timestamp getTimestamp(String columnName) throws SQLException
columnName
- is the SQL name of the column
public InputStream getAsciiStream(String columnName) throws SQLException
Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a get method implicitly closes the stream.
columnName
- is the SQL name of the column
public InputStream getUnicodeStream(String columnName) throws SQLException
Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a get method implicitly closes the stream.
columnName
- is the SQL name of the column
public InputStream getBinaryStream(String columnName) throws SQLException
Note: All the data in the returned stream must be read prior to getting the value of any other column. The next call to a get method implicitly closes the stream.
columnName
- is the SQL name of the column
public SQLWarning getWarnings() throws SQLException
The first warning reported by calls on this ResultSet is returned. Subsequent ResultSet warnings will be chained to this SQLWarning.
The warning chain is automatically cleared each time a new row is read.
Note: This warning chain only covers warnings caused by ResultSet methods. Any warning caused by statement methods (such as reading OUT parameters) will be chained on the Statement object.
public void clearWarnings() throws SQLException
public String getCursorName() throws SQLException
In SQL, a result table is retrieved through a cursor that is named. The current row of a result can be updated or deleted using a positioned update/delete statement that references the cursor name.
JDBC supports this SQL feature by providing the name of the SQL cursor used by a ResultSet. The current row of a ResultSet is also the current row of this SQL cursor.
Note: If positioned update is not supported a SQLException is thrown
public ResultSetMetaData getMetaData() throws SQLException
public Object getObject(int columnIndex) throws SQLException
Get the value of a column in the current row as a Java object.
This method will return the value of the given column as a Java object. The type of the Java object will be the default Java Object type corresponding to the column's SQL type, following the mapping specified in the JDBC spec.
This method may also be used to read datatabase specific abstract data types.
columnIndex
- the first column is 1, the second is 2, ...
public Object getObject(String columnName) throws SQLException
Get the value of a column in the current row as a Java object.
This method will return the value of the given column as a Java object. The type of the Java object will be the default Java Object type corresponding to the column's SQL type, following the mapping specified in the JDBC spec.
This method may also be used to read datatabase specific abstract data types.
columnName
- is the SQL name of the column
public int findColumn(String columnName) throws SQLException
columnName
- the name of the column
public Reader getCharacterStream(int columnIndex) throws SQLException
Get the value of a column in the current row as a java.io.Reader.
public Reader getCharacterStream(String columnName) throws SQLException
Get the value of a column in the current row as a java.io.Reader.
public BigDecimal getBigDecimal(int columnIndex) throws SQLException
columnIndex
- the first column is 1, the second is 2, ...
public BigDecimal getBigDecimal(String columnName) throws SQLException
public boolean isBeforeFirst() throws SQLException
Determine if the cursor is before the first row in the result set.
public boolean isAfterLast() throws SQLException
Determine if the cursor is after the last row in the result set.
public boolean isFirst() throws SQLException
Determine if the cursor is on the first row of the result set.
public boolean isLast() throws SQLException
Determine if the cursor is on the last row of the result set. Note: Calling isLast() may be expensive since the JDBC driver might need to fetch ahead one row in order to determine whether the current row is the last row in the result set.
public void beforeFirst() throws SQLException
Moves to the front of the result set, just before the first row. Has no effect if the result set contains no rows.
public void afterLast() throws SQLException
Moves to the end of the result set, just after the last row. Has no effect if the result set contains no rows.
public boolean first() throws SQLException
Moves to the first row in the result set.
public boolean last() throws SQLException
Moves to the last row in the result set.
public int getRow() throws SQLException
Determine the current row number. The first row is number 1, the second number 2, etc.
public boolean absolute(int row) throws SQLException
Move to an absolute row number in the result set.
If row is positive, moves to an absolute row with respect to the beginning of the result set. The first row is row 1, the second is row 2, etc.
If row is negative, moves to an absolute row position with respect to the end of result set. For example, calling absolute(-1) positions the cursor on the last row, absolute(-2) indicates the next-to-last row, etc.
An attempt to position the cursor beyond the first/last row in the result set, leaves the cursor before/after the first/last row, respectively.
Note: Calling absolute(1) is the same as calling first(). Calling absolute(-1) is the same as calling last().
public boolean relative(int rows) throws SQLException
Moves a relative number of rows, either positive or negative. Attempting to move beyond the first/last row in the result set positions the cursor before/after the the first/last row. Calling relative(0) is valid, but does not change the cursor position.
Note: Calling relative(1) is different than calling next() since is makes sense to call next() when there is no current row, for example, when the cursor is positioned before the first row or after the last row of the result set.
public boolean previous() throws SQLException
Moves to the previous row in the result set.
Note: previous() is not the same as relative(-1) since it makes sense to call previous() when there is no current row.
public void setFetchDirection(int direction) throws SQLException
public int getFetchDirection() throws SQLException
public void setFetchSize(int rows) throws SQLException
rows
- the number of rows to fetch
public int getFetchSize() throws SQLException
public void setKeysetSize(int keys) throws SQLException
rows
- the number of keys in a keyset
public int getKeysetSize() throws SQLException
public int getType() throws SQLException
public int getConcurrency() throws SQLException
public boolean rowUpdated() throws SQLException
public boolean rowInserted() throws SQLException
public boolean rowDeleted() throws SQLException
public void updateNull(int columnIndex) throws SQLException
public void updateBoolean(int columnIndex, boolean x) throws SQLException
public void updateByte(int columnIndex, byte x) throws SQLException
public void updateShort(int columnIndex, short x) throws SQLException
public void updateInt(int columnIndex, int x) throws SQLException
public void updateLong(int columnIndex, long x) throws SQLException
public void updateFloat(int columnIndex, float x) throws SQLException
public void updateDouble(int columnIndex, double x) throws SQLException
public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException
public void updateString(int columnIndex, String x) throws SQLException
public void updateBytes(int columnIndex, byte[] x) throws SQLException
public void updateDate(int columnIndex, Date x) throws SQLException
public void updateTime(int columnIndex, Time x) throws SQLException
public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException
public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException
public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException
public void updateCharacterStream(int columnIndex, Reader reader, int length) throws SQLException
public void updateObject(int columnIndex, Object x, int scale) throws SQLException
public void updateObject(int columnIndex, Object x) throws SQLException
public void updateNull(String columnName) throws SQLException
public void updateBoolean(String columnName, boolean x) throws SQLException
public void updateByte(String columnName, byte x) throws SQLException
public void updateShort(String columnName, short x) throws SQLException
public void updateInt(String columnName, int x) throws SQLException
public void updateLong(String columnName, long x) throws SQLException
public void updateFloat(String columnName, float x) throws SQLException
public void updateDouble(String columnName, double x) throws SQLException
public void updateBigDecimal(String columnName, BigDecimal x) throws SQLException
public void updateString(String columnName, String x) throws SQLException
public void updateBytes(String columnName, byte[] x) throws SQLException
public void updateDate(String columnName, Date x) throws SQLException
public void updateTime(String columnName, Time x) throws SQLException
public void updateTimestamp(String columnName, Timestamp x) throws SQLException
public void updateAsciiStream(String columnName, InputStream x, int length) throws SQLException
public void updateBinaryStream(String columnName, InputStream x, int length) throws SQLException
public void updateCharacterStream(String columnName, Reader reader, int length) throws SQLException
public void updateObject(String columnName, Object x, int scale) throws SQLException
public void updateObject(String columnName, Object x) throws SQLException
public void insertRow() throws SQLException
public void updateRow() throws SQLException
public void deleteRow() throws SQLException
public void refreshRow() throws SQLException
public void moveToInsertRow() throws SQLException
public void moveToCurrentRow() throws SQLException
public Object getObject(int i, Map map) throws SQLException
i
- the first column is 1, the second is 2, ...
map
- the mapping from SQL type names to Java classes
public Ref getRef(int i) throws SQLException
i
- the first column is 1, the second is 2, ...
public BlobLocator GetBlobLocator(int i) throws SQLException
i
- the first column is 1, the second is 2, ...
public ClobLocator getClobLocator(int i) throws SQLException
i
- the first column is 1, the second is 2, ...
public StructLocator getStructLocator(int i) throws SQLException
i
- the first column is 1, the second is 2, ...
public ArrayLocator getArrayLocator(int i) throws SQLException
i
- the first column is 1, the second is 2, ...
public Statement getStatement() throws SQLException
public Object getObject(String colName, Map map) throws SQLException
i
- the first column is 1, the second is 2, ...
map
- the mapping from SQL type names to Java classes
public Ref getRef(String colName) throws SQLException
i
- the column name
public BlobLocator GetBlobLocator(String colName) throws SQLException
i
- the column name
public ClobLocator getClobLocator(String colName) throws SQLException
i
- the column name
public StructLocator getStructLocator(String colName) throws SQLException
i
- the column name
public ArrayLocator getArrayLocator(String colName) throws SQLException
i
- the column name
Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |