What are the different methods of ResultSet?
We have seen earlier what ResultSet is and how we can change its behavior while setting the constant values. Now we will see what are the different methods of ResultSet and why they are used.
The following are methods of ResultSet Interface in JDBC
- boolean absolute(int row): This will move the cursor to the given row number in the ResultSet object.
- void afterLast(): This will move the cursor to the end of the ResultSet object, just after the last row.
- void beforeFirst(): This will move the cursor to the front of the ResultSet object, just before the first row.
- void cancelRowUpdates(): This will cancel the updates made to the current row.
- void clearWarnings(): This will clear all warnings reported on the ResultSet object.
- void close(): Releases this ResultSet object’s database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed.
- void deleteRow(): This will delete the current row from the ResultSet object and from the underlying database.
- int findColumn(String columnLabel): This will map the given ResultSet column name to its ResultSet column index.
- boolean first(): This will move the cursor to the first row in the ResultSet object.
- Array getArray(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as an Array object.
- Array getArray(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as an Array object.
- InputStream getAsciiStream(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a stream of ASCII characters.
- InputStream getAsciiStream(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a stream of ASCII characters.
- BigDecimal getBigDecimal(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.math.BigDecimal with full precision.
- BigDecimal getBigDecimal(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.math.BigDecimal with full precision.
- InputStream getBinaryStream(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a stream of uninterpreted bytes.
- InputStream getBinaryStream(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a stream of uninterpreted bytes.
- Blob getBlob(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a Blob object.
- Blob getBlob(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a Blob object.
- boolean getBoolean(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a boolean.
- boolean getBoolean(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a boolean.
- byte getByte(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a byte.
- byte getByte(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a byte.
- byte[] getBytes(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a byte array.
- byte[] getBytes(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a byte array.
- Reader getCharacterStream(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.io.Reader object.
- Reader getCharacterStream(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.io.Reader object.
- Clob getClob(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a Clob object.
- Clob getClob(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a Clob object.
- int getConcurrency(): To retrieve the concurrency mode of the ResultSet object.
- String getCursorName(): To retrieve the name of the SQL cursor used by this ResultSet object.
- Date getDate(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.sql.Date object.
- Date getDate(int columnIndex, Calendar cal): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.sql.Date object.
- Date getDate(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.sql.Date object.
- Date getDate(String columnLabel, Calendar cal): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.sql.Date object.
- double getDouble(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a double.
- double getDouble(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a double.
- int getFetchDirection(): To retrieve the fetch direction for this ResultSet object.
- int getFetchSize(): To retrieve the fetch size for this ResultSet object.
- float getFloat(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a float.
- float getFloat(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a float.
- int getHoldability(): To retrieve the holding ability of the ResultSet object
- int getInt(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as an int.
- int getInt(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as an int.
- long getLong(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a long.
- long getLong(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a long.
- ResultSetMetaData getMetaData(): To retrieve the number, types, and properties of the ResultSet object’s columns.
- Reader getNCharacterStream(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.io.Reader object.
- Reader getNCharacterStream(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.io.Reader object.
- NClob getNClob(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as an NClob object.
- NClob getNClob(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as an NClob object.
- String getNString(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a String.
- String getNString(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a String.
- Object getObject(int columnIndex): To get the value of the designated column(by index position) in the current row of the ResultSet object as an Object.
- <T> T getObject(int columnIndex, Class<T> type): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object and will convert from the SQL type of the column to the requested Java data type, if the conversion is supported.
- Object getObject(int columnIndex, Map<String, Class<?>> map): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as an Object.
- Object getObject(String columnLabel): To get the value of the designated column(by name) in the current row of the ResultSet object as an Object.
- <T> T getObject(String columnLabel, Class<T> type): To retrieve the value of the designated column(by name) in the current row of the ResultSet object and will convert from the SQL type of the column to the requested Java data type, if the conversion is supported.
- Object getObject(String columnLabel, Map<String, Class<?>> map): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as an Object.
- Ref getRef(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a Ref object.
- Ref getRef(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a Ref object.
- int getRow(): To retrieve the current row number.
- RowId getRowId(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.sql.RowId object.
- RowId getRowId(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.sql.RowId object.
- short getShort(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a short.
- short getShort(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a short.
- SQLXML getSQLXML(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet as a java.sql.SQLXML object.
- SQLXML getSQLXML(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet as a java.sql.SQLXML object.
- Statement getStatement(): To retrieve the Statement object that produced this ResultSet object.
- String getString(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a String.
- String getString(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a String.
- Time getTime(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.sql.Time object.
- Time getTime(int columnIndex, Calendar cal): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.sql.Time object.
- Time getTime(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.sql.Time object.
- Time getTime(String columnLabel, Calendar cal): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.sql.Time object.
- Timestamp getTimestamp(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.sql.Timestamp object.
- Timestamp getTimestamp(int columnIndex, Calendar cal): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.sql.Timestamp object.
- Timestamp getTimestamp(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.sql.Timestamp object.
- Timestamp getTimestamp(String columnLabel, Calendar cal): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.sql.Timestamp object.
- int getType(): To retrieve the type of the ResultSet object.
- URL getURL(int columnIndex): To retrieve the value of the designated column(by index position) in the current row of the ResultSet object as a java.net.URL object.
- URL getURL(String columnLabel): To retrieve the value of the designated column(by name) in the current row of the ResultSet object as a java.net.URL object.
- SQLWarning getWarnings(): To retrieve the first warning reported by calls on this ResultSet object.
- void insertRow(): To insert the contents of the insert row into this ResultSet object and into the database.
- boolean isAfterLast(): To check whether the cursor is after the last row in this ResultSet object.
- boolean isBeforeFirst(): To check whether the cursor is before the first row in this ResultSet object.
- boolean isClosed(): To check whether this ResultSet object has been closed.
- boolean isFirst(): To check whether the cursor is on the first row of the ResultSet object.
- boolean isLast(): To check whether the cursor is on the last row of the ResultSet object.
- boolean last(): To move the cursor to the last row in this ResultSet object and returns true/false.
- void moveToCurrentRow(): To move the cursor to the remembered cursor position, usually the current row.
- void moveToInsertRow(): To move the cursor to the insert row.
- boolean next(): To move the cursor forward one row from its current position.
- boolean previous(): To move the cursor to the previous row in this ResultSet object.
- void refreshRow(): To refresh the current row with its most recent value in the database.
- boolean relative(int rows): To move the cursor to a relative number of rows, either positive or negative.
- boolean rowDeleted(): To retrieve whether a row has been deleted.
- boolean rowInserted(): To retrieve whether the current row has had an insertion.
- boolean rowUpdated(): To retrieve whether the current row has been updated.
- void setFetchDirection(int direction): To give a hint as to the direction in which the rows in the ResultSet object will be processed.
- void setFetchSize(int rows): To give the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for this ResultSet object.
- void updateArray(int columnIndex, Array x): To update the designated column(by index position) with a java.sql.Array value.
- void updateArray(String columnLabel, Array x): To update the designated column(by name) with a java.sql.Array value.
- void updateAsciiStream(int columnIndex, InputStream x): To update the designated column(by index position) with an ASCII stream value.
- void updateAsciiStream(int columnIndex, InputStream x, int length): To update the designated column(by index position) with an ASCII stream value, which will have the specified number of bytes.
- void updateAsciiStream(int columnIndex, InputStream x, long length): To update the designated column(by index position) with an ASCII stream value, which will have the specified number of bytes.
- void updateAsciiStream(String columnLabel, InputStream x): To update the designated column(by name) with an ASCII stream value.
- void updateAsciiStream(String columnLabel, InputStream x, int length): To update the designated column(by name) with an ASCII stream value, which will have the specified number of bytes.
- void updateAsciiStream(String columnLabel, InputStream x, long length): To update the designated column(by name) with an ASCII stream value, which will have the specified number of bytes.
- void updateBigDecimal(int columnIndex, BigDecimal x): To update the designated column(by index position) with a java.math.BigDecimal value.
- void updateBigDecimal(String columnLabel, BigDecimal x): To update the designated column(by name) with a java.sql.BigDecimal value.
- void updateBinaryStream(int columnIndex, InputStream x): To update the designated column(by index position) with a binary stream value.
- void updateBinaryStream(int columnIndex, InputStream x, int length): To update the designated column(by index position) with a binary stream value, which will have the specified number of bytes.
- void updateBinaryStream(int columnIndex, InputStream x, long length): To update the designated column(by index position) with a binary stream value, which will have the specified number of bytes.
- void updateBinaryStream(String columnLabel, InputStream x): To update the designated column(by name) with a binary stream value.
- void updateBinaryStream(String columnLabel, InputStream x, int length): To update the designated column(by name) with a binary stream value, which will have the specified number of bytes.
- void updateBinaryStream(String columnLabel, InputStream x, long length): To update the designated column(by name) with a binary stream value, which will have the specified number of bytes.
- void updateBlob(int columnIndex, Blob x): To update the designated column(by index position) with a java.sql.Blob value.
- void updateBlob(int columnIndex, InputStream inputStream): To update the designated column(by index position) using the given input stream.
- void updateBlob(int columnIndex, InputStream inputStream, long length): To update the designated column(by index position) using the given input stream, which will have the specified number of bytes.
- void updateBlob(String columnLabel, Blob x): To update the designated column(by name) with a java.sql.Blob value.
- void updateBlob(String columnLabel, InputStream inputStream): To update the designated column(by name) using the given input stream.
- void updateBlob(String columnLabel, InputStream inputStream, long length): To update the designated column(by name) using the given input stream, which will have the specified number of bytes.
- void updateBoolean(int columnIndex, boolean x): To update the designated column(by index position) with a boolean value.
- void updateBoolean(String columnLabel, boolean x): To update the designated column(by name) with a boolean value.
- void updateByte(int columnIndex, byte x): To update the designated column(by index position) with a byte value.
- void updateByte(String columnLabel, byte x): To update the designated column(by name) with a byte value.
- void updateBytes(int columnIndex, byte[] x): To update the designated column(by index position) with a byte array value.
- void updateBytes(String columnLabel, byte[] x): To update the designated column(by name) with a byte array value.
- void updateCharacterStream(int columnIndex, Reader x): To update the designated column(by index position) with a character stream value.
- void updateCharacterStream(int columnIndex, Reader x, int length): To update the designated column(by index position) with a character stream value, which will have the specified number of bytes.
- void updateCharacterStream(int columnIndex, Reader x, long length): To update the designated column(by index position) with a character stream value, which will have the specified number of bytes.
- void updateCharacterStream(String columnLabel, Reader reader): To update the designated column(by name) with a character stream value.
- void updateCharacterStream(String columnLabel, Reader reader, int length): To update the designated column(by name) with a character stream value, which will have the specified number of bytes.
- void updateCharacterStream(String columnLabel, Reader reader, long length): To update the designated column(by name) with a character stream value, which will have the specified number of bytes.
- void updateClob(int columnIndex, Clob x): To update the designated column(by index position) with a java.sql.Clob value.
- void updateClob(int columnIndex, Reader reader): To update the designated column(by index position) using the given Reader object.
- void updateClob(int columnIndex, Reader reader, long length): To update the designated column(by index position) using the given Reader object, which is the given number of characters long.
- void updateClob(String columnLabel, Clob x): To update the designated column(by name) with a java.sql.Clob value.
- void updateClob(String columnLabel, Reader reader): To update the designated column(by name) using the given Reader object.
- void updateClob(String columnLabel, Reader reader, long length): To update the designated column(by name) using the given Reader object, which is the given number of characters long.
- void updateDate(int columnIndex, Date x): To update the designated column(by index position) with a java.sql.Date value.
- void updateDate(String columnLabel, Date x): To update the designated column(by name) with a java.sql.Date value.
- void updateDouble(int columnIndex, double x): To update the designated column(by index position) with a double value.
- void updateDouble(String columnLabel, double x): To update the designated column(by name) with a double value.
- void updateFloat(int columnIndex, float x): To update the designated column(by index position) with a float value.
- void updateFloat(String columnLabel, float x): To update the designated column(by name) with a float value.
- void updateInt(int columnIndex, int x): To update the designated column(by index position) with an int value.
- void updateInt(String columnLabel, int x): To update the designated column(by name) with an int value.
- void updateLong(int columnIndex, long x): To update the designated column(by index position) with a long value.
- void updateLong(String columnLabel, long x): To update the designated column(by name) with a long value.
- void updateNCharacterStream(int columnIndex, Reader x): To update the designated column(by index position) with a character stream value.
- void updateNCharacterStream(int columnIndex, Reader x, long length): To update the designated column(by index position) with a character stream value, which will have the specified number of bytes.
- void updateNCharacterStream(String columnLabel, Reader reader): To update the designated column(by name) with a character stream value.
- void updateNCharacterStream(String columnLabel, Reader reader, long length): To update the designated column(by name) with a character stream value, which will have the specified number of bytes.
- void updateNClob(int columnIndex, NClob nClob): To update the designated column(by index position) with a java.sql.NClob value.
- void updateNClob(int columnIndex, Reader reader): To update the designated column(by index position) using the given Reader The data will be read from the stream as needed until end-of-stream is reached.
- void updateNClob(int columnIndex, Reader reader, long length): To update the designated column(by index position) using the given Reader object, which is the given number of characters long.
- void updateNClob(String columnLabel, NClob nClob): To update the designated column(by name) with a java.sql.NClob value.
- void updateNClob(String columnLabel, Reader reader): To update the designated column(by name) using the given Reader object.
- void updateNClob(String columnLabel, Reader reader, long length): To update the designated column(by name) using the given Reader object, which is the given number of characters long.
- void updateNString(int columnIndex, String nString): To update the designated column(by index position) with a String value.
- void updateNString(String columnLabel, String nString): To update the designated column(by name) with a String value.
- void updateNull(int columnIndex): To update the designated column(by index position) with a null value.
- void updateNull(String columnLabel): To update the designated column(by name) with a null value.
- void updateObject(int columnIndex, Object x): To update the designated column(by index position) with an Object value.
- void updateObject(int columnIndex, Object x, int scaleOrLength): To update the designated column(by index position) with an Object value.
- default void updateObject(int columnIndex, Object x, SQLType targetSqlType): To update the designated column(by index position) with an Object value.
- default void updateObject(int columnIndex, Object x, SQLType targetSqlType, int scaleOrLength): To update the designated column(by index position) with an Object value.
- void updateObject(String columnLabel, Object x): To update the designated column(by name) with an Object value.
- void updateObject(String columnLabel, Object x, int scaleOrLength): To update the designated column(by name) with an Object value.
- default void updateObject(String columnLabel, Object x, SQLType targetSqlType): To update the designated column(by name) with an Object value.
- default void updateObject(String columnLabel, Object x, SQLType targetSqlType, int scaleOrLength): To update the designated column(by name) with an Object value.
- void updateRef(int columnIndex, Ref x): To update the designated column(by index position) with a java.sql.Ref value.
- void updateRef(String columnLabel, Ref x): To update the designated column(by name) with a java.sql.Ref value.
- void updateRow(): To update the underlying database with the new contents of the current row of the ResultSet object.
- void updateRowId(int columnIndex, RowId x): To update the designated column(by index position) with a RowId value.
- void updateRowId(String columnLabel, RowId x): To update the designated column(by name) with a RowId value.
- void updateShort(int columnIndex, short x): To update the designated column(by index position) with a short value.
- void updateShort(String columnLabel, short x): To update the designated column(by name) with a short value.
- void updateSQLXML(int columnIndex, SQLXML xmlObject): To update the designated column(by index position) with a java.sql.SQLXML value.
- void updateSQLXML(String columnLabel, SQLXML xmlObject): To update the designated column(by name) with a java.sql.SQLXML value.
- void updateString(int columnIndex, String x): To update the designated column(by index position) with a String value.
- void updateString(String columnLabel, String x): To update the designated column(by name) with a String value.
- void updateTime(int columnIndex, Time x): To update the designated column(by index position) with a java.sql.Time value.
- void updateTime(String columnLabel, Time x): To update the designated column(by name) with a java.sql.Time value.
- void updateTimestamp(int columnIndex, Timestamp x): To update the designated column(by index position) with a java.sql.Timestamp value.
- void updateTimestamp(String columnLabel, Timestamp x): To update the designated column(by name) with a java.sql.Timestamp value.
- boolean wasNull(): To check whether the last column read had a value of SQL NULL.