EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #70 background imageLoading...
Page #70 background image
v Use the CallableStatement.registerOutParameter call to specify that an output
parameter is of type BLOB. Then you can retrieve the parameter value into any
variable that has a data type that is compatible with a BLOB data type. For
example, the following code lets you retrieve a BLOB value into a byte[]
variable:
cstmt.registerOutParameter(parmIndex, java.sql.Types.BLOB);
cstmt.execute();
byte[] byteData = cstmt.getBytes(parmIndex);
Input parameters for CLOB columns
For input parameters for CLOB columns, or input/output parameters that are used
for input to CLOB columns, you can use one of the following techniques:
v Use a java.sql.Clob input variable, which is an exact match for a CLOB column:
cstmt.setClob(parmIndex, clobData);
v Use a CallableStatement.setObject call that specifies that the target data type is
CLOB:
String charData = "CharacterString";
cstmt.setObject(parmInd, charData, java.sql.Types.CLOB);
v Use one of the following types of stream input parameters:
–Ajava.io.StringReader input parameter with a cstmt.setCharacterStream
call:
java.io.StringReader reader = new java.io.StringReader(charData);
cstmt.setCharacterStream(parmIndex, reader, charData.length);
–Ajava.io.ByteArrayInputStream parameter with a cstmt.setAsciiStream
call, for ASCII data:
byte[] charDataBytes = charData.getBytes("US-ASCII");
java.io.ByteArrayInputStream byteStream =
new java.io.ByteArrayInputStream (charDataBytes);
cstmt.setAsciiStream(parmIndex, byteStream, charDataBytes.length);
For these calls, you need to specify the exact length of the input data.
v Use a String input parameter with a cstmt.setString call:
cstmt.setString(charData);
If the length of the data is greater than 32KB, and the JDBC driver has no
DESCRIBE information about the parameter data type, the JDBC driver assigns
the CLOB data type to the input data.
v Use a String input parameter with a cstmt.setObject call, and specify the target
data type as VARCHAR or LONGVARCHAR:
cstmt.setObject(parmIndex, charData, java.sql.Types.VARCHAR);
If the length of the data is greater than 32KB, and the JDBC driver has no
DESCRIBE information about the parameter data type, the JDBC driver assigns
the CLOB data type to the input data.
Output parameters for CLOB columns
For output parameters for CLOB columns, or input/output parameters that are
used for output from CLOB columns, you can use one of the following techniques:
v Use the CallableStatement.registerOutParameter call to specify that an output
parameter is of type CLOB. Then you can retrieve the parameter value into any
54 Application Programming Guide and Reference for Java
â„¢

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability