2. If inserts can be visible to the ResultSet, call the
DatabaseMetaData.insertsAreDetected method to determine whether the given
type of ResultSet can detect inserts.
3. If the ResultSet can detect inserts, call the ResultSet.rowInserted method to
determine whether the current row is was inserted.
Calling stored procedures in JDBC applications
To call stored procedures, you invoke methods in the CallableStatement class.
The basic steps for calling a stored procedures are:
1. Invoke the Connection.prepareCall method with the CALL statement as its
argument to create a CallableStatement object.
Restriction: The parameter types that are permitted depend on whether the
data source supports dynamic execution of the CALL statement. DB2 for z/OS
does not support dynamic execution of the CALL statement. For a call to a
stored procedure that is on a DB2 for z/OS database server, the parameters can
be parameter markers or literals, but not expressions. The following table lists
the types of literals that are supported, and the JDBC types to which they map.
Table 8. Supported literal types in parameters in DB2 for z/OS stored procedure calls
Literal parameter type JDBC type Examples
Integer java.sql.Types.INTEGER -122, 40022, +27
Floating-point decimal java.sql.Types.DOUBLE 23E12, 40022E-4, +2723E+15, 1E+23, 0E0
Fixed-point decimal java.sql.Types.DECIMAL -23.12, 40022.4295, 0.0, +2723.23, 10000000000
Character java.sql.Types.VARCHAR ’Grantham Lutz’, ’O’’Conner’, ’ABcde?z?’
Hexadecimal java.sql.Types.VARBINARY X’C1C30427’, X’00CF18E0’
Unicode string java.sql.Types.VARCHAR UX’0041’, UX’0054006500730074’
2. Invoke the CallableStatement.setXXX methods to pass values to the input
parameters (parameters that are defined as IN in the CREATE PROCEDURE
statement).
Restriction: If the data source does not support dynamic execution of the
CALL statement, you must specify the data types for CALL statement input
parameters exactly as they are specified in the stored procedure definition.
3. Invoke the CallableStatement.registerOutParameter method to indicate which
parameters are output-only parameters (parameters that are defined as OUT in
the CREATE PROCEDURE statement) or input and output parameters
(parameters that are defined as INOUT in the CREATE PROCEDURE
statement).
Restriction: If the data source does not support dynamic execution of the
CALL statement, you must specify the data types for CALL statement
output-only or input and output parameters exactly as they are specified in the
stored procedure definition.
4. Invoke one of the following methods to call the stored procedure:
CallableStatement.executeUpdate
Invoke this method if the stored procedure does not return result sets.
CallableStatement.executeQuery
Invoke this method if the stored procedure returns one result set.
Chapter 3. JDBC application programming 45
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|||
|||
|||
|||
|||
|||
|||
|
|