Scrollable ResultSet

  • It is a interface. A ResultSet object maintains a cursor pointing to its current row of data
  • ResultSet provides access to a table of data generated by executing a Statement. The table rows are retrieved in sequence. A ResultSet maintains a cursor pointing to its current row of data. The next() method is used to successively step through the rows of the tabular results
  • next() method is used to move the cursor to next position.
  • A ResultSet object maintains a cursor that enables you to move through the rows stored in a ResultSet object.

Types of ResultSet:

There is three types of ResultSet object-
  1. TYPE_ FORWARD ONLY: The Result Set is not scrollable that means the cursor can move only forward direction before first row to last row.
  2. TYPE_SCROLL INSENSITIVE: This ResultSet is scrollable, its cursor can move both forward or backword direction .
  3. TYPE_SCROLL SENSITIVE: This ResultSet is scrollable, its cursor can move both forward and backword direction to the current position and it can move to an absolute position.
There are the different types of method in ResutSetScrollableData, some mostly used described here.
  • First();- This method move the cursor to the first row of the data table.
  • Last(); This method move the cursor to last row of the data table.
  • Previous(); This method move the cursor current row to back row.
  • Next(); This method move the cursor next row.
  • Absolute(); This method move the cursor at the given row.
  • Relative(); This method Moves the cursor a relative number of rows, either positive or negative
  • Scrollable ResultSet : Result Set Scrollabale set allows the cursor to be moved to any row in the Result Set Back and forward


ResultSetMetaData

  • The simple meaning of metadata is data about data.
  • There are two metadata available in the JDBC API -ResultSetMetaData and DatabaseMetaData.
  • Result Set Meta Data is a interface that can be used to get information about the type and properties of the columns in a ResultSet object.
  • ResultSetMetaData is used to make descriptive information about ResultSet object, like; number of columns, name of columns and datatype of columns.
  • It does not provide any information regarding database and how many rows are available in the ResultSet object.
  • First we have to create object of ResultSetMetadata by calling getMetaData() method from ResultSet object.
  • Syntax :
    	ResultSetMetaData rsmd=res.getMeataData(); 
    	// res is a valid object of ResultSet object 
    			
  • The following are common methods in ResultSetMetadata interface -
  • int getColumnCount()     String getColumnName()
    int getColumnType()      String getTableName()
  • The following is the source code to demostrates ResultSetMetaData interface. Here user will input table name and display the result with column heading-