Oracle 5.0 Reference Manual page 2112

Table of Contents

Advertisement

Example 20.7. Connector/J: Retrieving results and output parameter values
...
boolean hadResults = cStmt.execute();
//
// Process all returned result sets
//
while (hadResults) {
}
//
// Retrieve output parameters
//
// Connector/J supports both index-based and
// name-based retrieval
//
int outputValue = cStmt.getInt(2); // index-based
outputValue = cStmt.getInt("inOutParam"); // name-based
...
20.3.6.4. Retrieving
Before version 3.0 of the JDBC API, there was no standard way of retrieving key values from
databases that supported auto increment or identity columns. With older JDBC drivers for MySQL, you
could always use a MySQL-specific method on the
LAST_INSERT_ID()
the MySQL-specific method call isn't portable, and issuing a
key's value requires another round-trip to the database, which isn't as efficient as possible. The
following code snippets demonstrate the three different ways to retrieve
First, we demonstrate the use of the new JDBC 3.0 method
preferred method to use if you need to retrieve
3.0. The second example shows how you can retrieve the same value using a standard
LAST_INSERT_ID()
AUTO_INCREMENT
Example 20.8. Connector/J: Retrieving
Statement.getGeneratedKeys()
Statement stmt = null;
ResultSet rs = null;
try {
//
// Create a Statement instance that we can use for
// 'normal' result sets assuming you have a
// Connection 'conn' to a MySQL database already
// available
stmt = conn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,
//
// Issue the DDL queries for the table for this example
ResultSet rs = cStmt.getResultSet();
// process result set
...
hadResults = cStmt.getMoreResults();
AUTO_INCREMENT
after issuing an
query. The final example shows how updatable result sets can retrieve the
value when using the
JDBC Concepts
Column Values through JDBC
Statement
to a table that had an
INSERT
AUTO_INCREMENT
method.
insertRow()
AUTO_INCREMENT
java.sql.ResultSet.CONCUR_UPDATABLE);
2092
interface, or issue the query
AUTO_INCREMENT
to get the
SELECT
AUTO_INCREMENT
AUTO_INCREMENT
getGeneratedKeys()
keys and have access to JDBC
column values using
SELECT
key. Using
values.
which is now the
SELECT

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents