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.
String s;
Connection con;
Statement stmt;
ResultSet rs;
...
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE); 1
// Create a Statement object
// for a scrollable, updatable
// ResultSet
rs = stmt.executeQuery("SELECT EMPNO FROM EMPLOYEE FOR UPDATE OF PHONENO");
// Create the ResultSet 3
rs.afterLast(); // Position the cursor at the end of
// the ResultSet 4a
while (rs.previous()) { // Position the cursor backward
s = rs.getString("EMPNO"); // Retrieve the employee number 4d
// (column 1 in the result
// table)
System.out.println("Employee number="+s);
// Print the column value
if (s.compareTo("000010") == 0) { // Look for employee 000010
rs.updateString("PHONENO","4657"); // Update their phone number
rs.updateRow(); // Update the row
}
}
rs.close(); // Close the ResultSet 5
stmt.close(); // Close the Statement 6
Figure 15. Using a scrollable cursor
Chapter 3. JDBC application programming 41
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|