IBM DB2 Manual page 57

Table of Contents

Advertisement

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String s;
Connection con;
Statement stmt;
ResultSet rs;
...
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
rs = stmt.executeQuery("SELECT EMPNO FROM EMPLOYEE FOR UPDATE OF PHONENO");
rs.afterLast();
while (rs.previous()) {
s = rs.getString("EMPNO");
System.out.println("Employee number = " + s);
if (s.compareTo("000010") == 0) {
rs.updateString("PHONENO","4657");
rs.updateRow();
}
}
rs.close();
stmt.close();
Figure 15. Using a scrollable cursor
Related concepts
"Characteristics of a JDBC ResultSet under the IBM Data Server Driver for
JDBC and SQLJ" on page 37
Related tasks
"Retrieving data from tables using the Statement.executeQuery method" on
page 32
Multi-row SQL operations with the IBM Data Server Driver for JDBC and SQLJ:
IBM Data Server Driver for JDBC and SQLJ supports multi-row INSERT, UPDATE,
and FETCH for connections to data sources that support these operations.
Multi-row INSERT
When you execute multiple INSERT statements in a batch, and the data source
supports multi-row INSERT, the IBM Data Server Driver for JDBC and SQLJ uses
multi-row INSERT to insert the rows. Multi-row INSERT can provide better
performance than individual INSERT statements.
You cannot execute a multi-row insert operation by including a multi-row INSERT
statement in your JDBC application.
Multi-row FETCH
Multi-row FETCH can provide better performance than retrieving one row with
each FETCH statement. For IBM Data Server Driver for JDBC and SQLJ type 2
connectivity on DB2 for z/OS, multi-row FETCH can be used for forward-only
cursors and scrollable cursors. For other types of connectivity, multi-row FETCH
can be used only for scrollable cursors.
ResultSet.CONCUR_UPDATABLE);
// Create a Statement object
// for a scrollable, updatable
// ResultSet
// Create the ResultSet
// Position the cursor at the end of
// the ResultSet
// Position the cursor backward
// Retrieve the employee number 4d
// (column 1 in the result
// table)
// Print the column value
// Look for employee 000010
// Update their phone number
// Update the row
// Close the ResultSet
// Close the Statement
Chapter 3. JDBC application programming
1
3
4a
5
6
41

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents