AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-jdbc: Difference between ScrollSensitive and ScrollInsensitive ResultSet?

1)What is the difference between ScrollSensitive ResultSet and ScrollInsensitive ResultSets?

2) What is the default ResultSet type in JDBC application and How it is possible to create a specific
type of ResultSet object?

3) How to iterate the data from Scrollable ResultSet objuect in both forward and backword
direction?


Could you plz explain the above mention questions with sample example code.

corejava x 353
jdbc x 32
Posted On : 2016-09-19 07:22:48.0
profile MOHAMMAD SALEEM BASHA - anyforum.in MOHAMMAD SALEEM BASHA
267150
up-rate
4
down-rate

Answers


When you create a result set under JDBC 2.0 functionality, you must choose a particular result set type to specify whether the result set is scrollable/positional and sensitive to underlying database changes.

If the JDBC 1.0 functionality is all you desire, JDBC 2.0 continues to support this through the forward-only result set type. A forward-only result set cannot be sensitive.

If you want a scrollable result set, then you must also specify sensitivity. Specify the scroll-sensitive type for the result set to be scrollable and sensitive to underlying changes. Specify the scroll-insensitive type for the result set to be scrollable but not sensitive to underlying changes.

To summarize, the following result set types are available with JDBC 2.0:

Forward-only:
------------------------------------------------
This is a JDBC 1.0 functionality. This type of result set is not scrollable, not positionable, and not sensitive.

Scroll-sensitive:
--------------------------------------------
This type of result set is scrollable and positionable. It is also sensitive to underlying database changes.

Scroll-insensitive:
-----------------------------------------------
This type of result set is scrollable and positionable, but not sensitive to underlying database changes.

Note:
-----------------------------
The sensitivity of a scroll-sensitive result set is affected by fetch size.

Specifying Result Set Scrollability and Updatability:
--------------------------------------------------------------------------------------------------
Under JDBC 2.0, the Connection class has the following methods that take a result set type and a concurrency type as input:

* Statement createStatement(int resultSetType, int resultSetConcurrency)
* PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
* CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency)

The statement objects created will have the intelligence to produce the appropriate kind of result sets.

You can specify one of the following static constant values for result set type:

ResultSet.TYPE_FORWARD_ONLY
ResultSet.TYPE_SCROLL_INSENSITIVE
ResultSet.TYPE_SCROLL_SENSITIVE

Tip:
-----------------------
"Oracle Implementation of Scroll-Sensitive Result Sets"
And you can specify one of the following static constant values for concurrency type:
ResultSet.CONCUR_READ_ONLY
ResultSet.CONCUR_UPDATABLE


After creating a Statement, PreparedStatement, or CallableStatement object, you can verify its result set type and concurrency type by calling the following methods on the statement object:

int getResultSetType() throws SQLException
int getResultSetConcurrency() throws SQLException


Example Prepared Statement Object With Result Set:
-----------------------------------------------------------------------------------------------
Following is an example of a prepared statement object that specifies a scroll-sensitive and updatable result set for queries run through that statement:

...
PreparedStatement pstmt = conn.prepareStatement
("SELECT empno, sal FROM emp WHERE empno = ?",
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

pstmt.setString(1, "28959");
ResultSet rs = pstmt.executeQuery();
...


For more information visit following links:
Oracle- JDBC- Click Here

Posted On : 2016-09-19 13:52:10
Satisfied : 0 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523188222642
Reply This Thread
up-rate
0
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in