Cursors


Overview

JDBC provides simple cursor support. An application can use ResultSet.getCursorName() to obtain a cursor associated with the current ResultSet. It can then use this cursor name in positioned update or positioned delete statements.

The cursor will remain valid until the ResultSet or its parent Statement is closed.

Note that not all DBMSs support positioned update and delete. The DatabaseMetaData.supportsPositionedDelete and supportsPositionedUpdate methods can be used to discover whether a particular connection supports these operations. When they are supported, the DBMS/driver must insure that rows selected are properly locked so that positioned updates do not result in update anomalies or other concurrency problems.

The Statement.setCursorName() method provides a way for an application to specify a cursor name for the cursor associated with the next result set produced by a statement. A result set's cursor name can be retrieved by calling ResultSet.getCursorName(). If Statement.setCursorName() is called prior to creating a result set, then ResultSet.getCursorName() should always return the value specified in Statement.setCursorName().

Note that calling Statement.setCursorName() prior to creating a result set does not mean that the result set is updatable, in other words, positioned update or delete may not be allowed on a result set even if Statement.setCursorName() was called. By default , a result set is read-only.

The only use for a cursor name is to embed it in a SQL statement of the form

UPDATE ... WHERE CURRENT OF <cursor>

The cursor name provides a way to do a positioned update or delete. To enable positioned update and delete on a result set, a select query of the form

SELECT FOR UPDATE ... FROM ... WHERE ...

should be used to create the result set. If Statement.setCursorName() is not called to specify a cursor name, then the JDBC driver or underlying DBMS must generate a cursor name when a SELECT FOR UPDATE statement is executed, if positioned update/delete is supported. ResultSet.getCursorName()should return null if the result set is read-only and Statement.setCursorName() was not called to specify a cursor name.

Character conversion

JDBC driver implementations are expected to automatically convert the Java programming language unicode encoding of strings and characters to and from the character encoding of the database being accessed. The JDBC API does not define how to override the character encoding of a database. For example, the API does not define how to store unicode characters in an ASCII database.