|
|
These methods require a valid ResultSet object, returned from the getResultSet() method.
resultset.absolute(int row)
Moves the cursor to the specified row from the result set (rows start at 1). You can use a negative number to move to a row starting from the end of the result set. Returns true if the cursor is on the row, false if not.
resultset.afterlast()
Moves the cursor to the end of the result set.
resultset.beforeFirst()
Moves the cursor to the start of the result set.
resultset.cancelRowUpdates()
Cancels updates made to the current row in the result set.
resultset.close()
Closes the result set and frees all associated resources.
resultset.deleteRow()
Deletes the current ResultSet row from the database (and the result set).
resultset.findColumn(String field_name)
Maps the fieldname to the column in the result set and returns the column index as an integer.
resultset.first()
Moves the cursor to the first row in the result set. Returns true if there is a valid first row, false if not.
resultset.getXXX(String fieldname | int fieldindex)
Returns the contents of a field of the specified type. You can identify the field by its name or its position.
Table F.3 shows the SQL types and their equivalent Java methods.
SQL Type | Java Method |
---|---|
BIGINT | getLong() |
BINARY | getBytes() |
BIT | getBoolean() |
BLOB | getBlob() |
CHAR | getString() |
DATE | getDate() |
DECIMAL | getBigDecimal() |
DOUBLE | getDouble() |
FLOAT | getDouble() |
INTEGER | getInt() |
LONGVARBINARY | getBytes() |
LONGVARCHAR | getString() |
NUMERIC | getBigDecimal() |
OTHER | getObject() |
REAL | getFloat() |
SMALLINT | getShort() |
TIME | getTime() |
TIMESTAMP | getTimestamp() |
TINYINT | getByte() |
VARBINARY | getBytes() |
VARCHAR | getString() |
resultset.getCursorName()
Returns the name of the cursor used by the result set.
resultset.getFetchSize()
Returns the fetch size for the result set object.
resultset.getMetaData()
Returns a ResultSetMetaData object with the number, type, and properties of the result set's columns.
resultset.getRow()
Returns an integer containing the current row number.
resultset.getStatement()
Returns the statement object that created the result set.
resultset.getType()
Returns the type of the result set object.
resultset.getWarnings()
Returns the first Warning triggered by a call from a ResultSet method on this result set.
resultset.insertRow()
Inserts the contents of the insert row into the database (and the result set).
resultet.isAfterLast()
Returns true if the cursor is after the last row in the result set, false if not.
resultset.isBeforeFirst()
Returns true if the cursor is before the first row in the result set, false if not.
resultset.isFirst()
Returns true if the cursor is at the first row in the result set, false if not.
resultset.isLast()
Returns true if the cursor is at the last row in the result set, false if not.
resultset.last()
Moves the cursor to the last row in the result set. Returns true if there is a valid last row, false if not.
resultset.moveToCurrentRow()
Moves the cursor to the remembered cursor position, which is usually the current row. This has no effect if the cursor is not on the insert row. See the moveToInsertRow() method.
resultset.moveToInsertRow()
Moves the cursor to the insert row (a buffer where a new row can be placed with an update method). It remembers the current cursor position, which can be returned to with the moveToCurrentRow() method.
resultset.next()
Moves the cursor to the next row in the result set and returns true if there is a next row, false if there is not (the end has been reached).
For example:
connection = DriverManager.getConnection(url, "guru2b", "g00r002b"); statement = connection.createStatement(); resultset = statement.executeQuery("SELECT first_name,surname FROM customer"); while(resultset.next()) { String first_name = resultset.getString("first_name"); String surname = resultset.getString("surname"); System.out.print("Name: " + first_name + " " + surname); }
resultset.previous()
Moves the cursor to the previous row in the result set and returns true if there is a previous row, false if there is not (the start has been reached).
For example:
while(resultset.previous()) { ... }
resultset.refreshRow()
Refreshes the current result set row with the most recent value in the database.
resultset.relative(int rows)
Moves the cursor forward (if rows is positive) or backward (if rows is negative) by rows number of positions.
resultset.rowDeleted()
Returns true if a row has been detected as deleted in the result set, false if not.
resultset.rowInserted()
Returns true if a row has been detected as inserted in the result set, false if not.
resultset.rowUpdated()
Returns true if a row has been detected as updated in the result set, false if not.
resultset.setFetchSize(int rows)
Gives the driver an idea of how many rows should be returned from the database when more rows are needed for the result set.
Updates the field with a value of the specified type. Table F.4 shows the SQL types and their equivalent Java methods.
SQL Type | Java Method |
---|---|
BIGINT | updateLong() |
BINARY | updateBytes() |
BIT | updateBoolean() |
BLOB | updateBlob() |
CHAR | updateString() |
DATE | updateDate() |
DECIMAL | updateBigDecimal() |
DOUBLE | updateDouble() |
FLOAT | updateDouble() |
INTEGER | updateInt() |
LONGVARBINARY | updateBytes() |
LONGVARCHAR | updateString() |
NUMERIC | updateBigDecimal() |
NULL | updateNull() |
OTHER | updateObject() |
REAL | updateFloat() |
SMALLINT | updateShort() |
TIME | updateTime() |
TIMESTAMP | updateTimestamp() |
TINYINT | updateByte() |
VARBINARY | updateBytes() |
VARCHAR | updateString() |
resultset.updateRow()
Updates the database with the contents of the current row of the result set.
resultSet.wasNull()
Returns true if the previous field read was a SQL NULL, false if not.
|
|