JDBC ResultSet Types and Concurrency

JDBC ResultSet Types and Concurrency

ResultSet Types Concurrency JDBC

Overloaded createStatement() Method (knowledge required for ResultSet Types Concurrency JDBC).

Before going into programming it is required to know more about createStatement() method of Connection interface. This method can have parameters. You know the following Statement object creation earlier.

Statement stmt = con.createStatement();

The createStatement() method of Connection interface returns an object of Statement interface. This you used earlier in the first program CreateTable. This createStatement() does not take any parameters. But createStatement() method is overloaded two times as follows.

Note: For brevity shown here one only.

createStatement(int parameter1, int parameter2): This overloaded method returns an object of Statement. Statement object comes with the properties of parameter1 and parameter2.

What are the values for parameter1 could be? (of ResultSet Types Concurrency JDBC)

The parameter1 tells the type of ResultSet.

  1. ResultSet.TYPE_FORWARD_ONLY: If the type is not mentioned, it is the default type of the ResultSet. The ResultSet is not scrollable. That is JDBC 2.0 methods like previous() or absolute() do not work. Only next() method works. Records cannot be printed in the reverse order.
  2. ResultSet.TYPE_SCROLL_INSENSITIVE: The type of the ResultSet object obtained is scrollable. The cursor can be placed on any specific record. Once the ResultSet object is retrieved using createStatement() method, any changes made in on the records of the table are NOT REFLECTED in the records. That is, ResultSet records contain OLD data only.
  3. ResultSet.TYPE_SCROLL_SENSITIVE: The type of the ResultSet object obtained is scrollable. Cursor can be placed on any specific record. Once the ResultSet object is retrieved using createStatement() method, any changes made in on the records of the table are REFLECTED in the records. That is, ResultSet records contain NEW data only.

What are the values for parameter2 could be? (of ResultSet Types Concurrency JDBC)

The prameter2 tells the type of Concurrency.

  1. ResultSet.CONCUR_READ_ONLY: If not mentioned, it is the default. The records of ResultSet are read mode only. That is any update() method does not work.
  2. ResultSet.CONCUR_UPDATABLE: The records of ResultSet are updatable. That is any update() method works.

The above ResultSet types and concurrency modes are passed to createStatement() method.

Snippet code of using ResultSet type and concurrency

Syntax:

createStatement(int type, int concurrency);

1. Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

2. Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

The above methods are used in subsequent programs like Creating Scrollable ResultSet and ResultSet Enhancement Update Methods and ResultSet Update Record with Refresh Row.

Pass your comments and suggestions to improve this tutorial "ResultSet Types Concurrency JDBC".

Leave a Reply

Your email address will not be published. Required fields are marked *