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 #153 background imageLoading...
Page #153 background image
Java data types for retrieving or updating LOB column data in
SQLJ applications
When the deferPrepares property is set to true, and the IBM Data Server Driver for
JDBC and SQLJ processes an uncustomized SQLJ statement that includes host
expressions, the driver might need to do extra processing to determine data types.
This extra processing can impact performance.
For IBM Data Server Driver for JDBC and SQLJ type 2 connectivity to DB2 for
z/OS, when the JDBC driver processes a CALL statement, the driver cannot
determine the parameter data types.
When the JDBC driver cannot immediately determine the data type of a parameter
that is used with a LOB column, you need to choose a parameter data type that is
compatible with the LOB data type.
Input parameters for BLOB columns
For input parameters for BLOB columns, you can use either of the following
techniques:
v Use a java.sql.Blob input variable, which is an exact match for a BLOB column:
java.sql.Blob blobData;
#sql {CALL STORPROC(:IN blobData)};
Before you can use a java.sql.Blob input variable, you need to create a
java.sql.Blob object, and then populate that object.
For example, if you are using IBM Data Server Driver for JDBC and SQLJ type 2
connectivity on DB2 for z/OS, you can use the IBM Data Server Driver for JDBC
and SQLJ-only method com.ibm.db2.jcc.t2zos.DB2LobFactory.createBlob to
create a java.sql.Blob object and populate the object with byte[] data:
byte[] byteArray = {0, 1, 2, 3};
java.sql.Blob blobData =
com.ibm.db2.jcc.t2zos.DB2LobFactory.createBlob(byteArray);
v Use an input parameter of type of sqlj.runtime.BinaryStream.A
sqlj.runtime.BinaryStream object is compatible with a BLOB data type. For this
call, you need to specify the exact length of the input data:
java.io.ByteArrayInputStream byteStream =
new java.io.ByteArrayInputStream(byteData);
int numBytes = byteData.length;
sqlj.runtime.BinaryStream binStream =
new sqlj.runtime.BinaryStream(byteStream, numBytes);
#sql {CALL STORPROC(:IN binStream)};
You cannot use this technique for input/output parameters.
Output parameters for BLOB columns
For output or input/output parameters for BLOB columns, you can use the
following technique:
v Declare the output parameter or input/output variable with a java.sql.Blob data
type:
java.sql.Blob blobData = null;
#sql CALL STORPROC (:OUT blobData)};
java.sql.Blob blobData = null;
#sql CALL STORPROC (:INOUT blobData)};
Chapter 4. SQLJ application programming 137

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