Cursors; Ansi Holdable Cursors In Jdbc Client Applications - HP Neoview SQL Reference Manual

Hide thumbs Also See for Neoview SQL:
Table of Contents

Advertisement

Cursors

The ANSI SQL standard defines a "cursor". Neoview uses a SQL cursor to manage an ODBC or
JDBC result set, which is created by executing a SQL statement. A cursor can be open or closed.
A cursor is opened after the SQL statement is executed. The ODBC SQLFetch() or JDBC next()
methods implicitly use the open cursor to retrieve rows from the result set. When the cursor is
closed before ODBC or JDBC has retrieved all rows from the result set, the result set is discarded.
After errors, Neoview SQL closes the cursor. Neoview SQL also closes the cursor if the transaction
in which it is operating is rolled back.
A transaction commit may also close the cursor, depending on whether the cursor is holdable
or non-holdable, as defined in the ANSI SQL standard. A non-holdable cursor is closed when
the transaction in which it is operating is committed.
A holdable cursor has these characteristics that differentiate it from a non-holdable cursor:
The cursor remains open when the transaction is committed with a COMMIT statement.
A new transaction is started automatically when a fetch follows a COMMIT statement.
Error [8013] is returned when an attempt is made to update or delete a row (using a positioned
update or delete) without a fetch after the transaction is committed.
Error [4382] is returned when an attempt is made to use the holdable cursor with a CALL
statement.
A publish/subscribe holdable cursor is a holdable cursor used with a SQL statement that uses
any of these publish/subscribe features in a SELECT statement:
Return a continuous data stream, by using STREAM as a table_ref
Create an embedded delete, by using a delete_statement as a table-ref
Create an embedded update, by using an update_statement as a table_ref
An ANSI holdable cursor is a holdable cursor that does not use the publish/subscribe features
listed here. ANSI holdable cursors are not allowed with the SERIALIZABLE or REPEATABLE
READ transaction isolation level.
ANSI holdable cursors are INSENSITIVE in Neoview SQL, which means that it is impossible to
predict whether insert, update, or delete operations made to rows in committed transactions in
which the cursor is held open will be visible through the cursor in subsequent transactions before
the cursor is closed. It is also impossible to predict whether the effects of such operations will be
visible through the cursor in the same trsnaction in which the changes are made.
A publish/subscribe holdable cursor differs from an ANSI holdable cursor in the following ways.
A publish/subscribe holdable cursor:
Remains open when a transaction is rolled back.
Is ASENSITIVE, unless the SQL SELECT statement contains an embedded update or
embedded delete, in which case, the cursor is SENSITIVE. A SENSITIVE cursor will be
sensitive to changes made to rows in its result set by any transaction committed while the
cursor is open.
Can be used with the SERIALIZABLE or REPEATABLE READ transaction isolation level.
HP recommends that the SERIALIZABLE or REPEATABLE READ transaction isolation
level should not be used with an ASENSITIVE holdable cursor.
Can be declared holdable after it is prepared, when ODBC is used.

ANSI Holdable Cursors in JDBC Client Applications

To specify a holdable cursor in a client application that uses the JDBC Type 4 driver, specify
HOLD_CURSORS_OVER_COMMIT as a resultSetHoldability parameter to one of these
Connection methods: createStatement or prepareStatement. For example, this code
creates a PreparedStatement object that specifies a holdable cursor:
PreparedStatement setSalary =
conn.prepareStatement("SELECT empnum " +
Cursors
239

Advertisement

Table of Contents
loading

Table of Contents