Welcome

JDBC Tutorial


JDBC Scrollable Resultset

     ResultSet Object is a container for given SQL Query. It contains SQL Query Data, and also describing each column(i.e metadata). By Default ResultSet rows navigates in Forward Directions, and it also possible to make ResultSet rows scrollable in Forward or Reverse Direction or moving to exact position etc.,. This is possible changing perameters at CreateStatement or Prepared Statement methods.

CreateStatement method in Connection Object has 3 overloaded methods
  • createstatement()
  •    CreateStatement without parameters is equal to createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY) JDBC driver implicitely uses these paramater values.

  • createstatement(int resultSetType, int resultSetConcurrency)
  •    Programmer can explicitely pass ResultSetType and ResultSetConcurrency, for forward or backward direction.

  • createstatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability)
  •    In this method, apart from resultset type and concurrency, programmer can set Holdability.

    Note: Same parameters applies to connection Object's PreparedStatement

JDBC API Scrollable ResultSet Programming

ResultSet Types
ResultSet TypeRemarks
ResultSet.TYPE_FORWARD_ONLY Result Set Object is read only.Cusror with in the Resultset moves only forward direction.
ResultSet.TYPE_SCROLL_INSENSITIVEResult Set Object is scrollable and Data with in ResultSet not updatable
ResultSet.TYPE_SCROLL_SENSITIVEResult Set Object is scrollable and Data with in ResultSet may be updatable

resultSetConcurrency a concurrency type; one of ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE

ResultSet Concurrency
ResultSet Concurrency TypeRemarks
ResultSet.CONCUR_READ_ONLY Result Set Object is read only.Cusror with in the Resultset moves only forward direction.
ResultSet.CONCUR_UPDATABLEResult Set Object is scrollable and Data with in ResultSet updatable
ResultSet Holdability
ResultSet Holdability TypeRemarks
ResultSet.CLOSE_CURSORS_AT_COMMIT If ResultSets with this Holdability, will be closed on committing the transaction
ResultSet.HOLD_CURSORS_OVER_COMMITIf ResultSets with this Holdability, will be open on committing the transaction


ResultSet Object has following methods for scrolling rows back and forth, moving to absolute location, update a row,delete a row etc.,

	boolean previous() 
	boolean first() 
	boolean last() 
	boolean absolute(int row) 
	boolean relative(int rows)
	void afterLast()
	void afterLast() 
	void beforeFirst() 
	void moveToCurrentRow() 
	void moveToInsertRow() 
	boolean isFirst() 
	boolean isBeforeFirst() 
	boolean isLast() 
	boolean isAfterLast() 
	int getRow() 
	
	deleterow
	updaterow
	insertrow
	cancelupdaterow
	

Scrolling Resultset in Reverse Direction

Scrolling Resultset in Forward Direction

Move to absolue Position in the Scrollable ResultSet

Scrolling Resultset in Forward Direction

Insert Row with Scrollable ResultSet

Update Row with Scrollable ResultSet

Delete Row with Scrollable ResultSet

ADS