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 #154 background imageLoading...
Page #154 background image
Input parameters for CLOB columns
For input parameters for 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:
#sql CALL STORPROC(:IN clobData)};
Before you can use a java.sql.Clob input variable, you need to create a
java.sql.Clob 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.createClob to
create a java.sql.Clob object and populate the object with String data:
String stringVal = "Some Data";
java.sql.Clob clobData =
com.ibm.db2.jcc.t2zos.DB2LobFactory.createClob(stringVal);
v Use one of the following types of stream input parameters:
–Asqlj.runtime.CharacterStream input parameter:
java.lang.String charData;
java.io.StringReader reader = new java.io.StringReader(charData);
sqlj.runtime.CharacterStream charStream =
new sqlj.runtime.CharacterStream (reader, charData.length);
#sql {CALL STORPROC(:IN charStream)};
–Asqlj.runtime.UnicodeStream parameter, for Unicode UTF-16 data:
byte[] charDataBytes = charData.getBytes("UnicodeBigUnmarked");
java.io.ByteArrayInputStream byteStream =
new java.io.ByteArrayInputStream(charDataBytes);
sqlj.runtime.UnicodeStream uniStream =
new sqlj.runtime.UnicodeStream(byteStream, charDataBytes.length );
#sql {CALL STORPROC(:IN uniStream)};
–Asqlj.runtime.AsciiStream parameter, for ASCII data:
byte[] charDataBytes = charData.getBytes("US-ASCII");
java.io.ByteArrayInputStream byteStream =
new java.io.ByteArrayInputStream (charDataBytes);
sqlj.runtime.AsciiStream asciiStream =
new sqlj.runtime.AsciiStream (byteStream, charDataBytes.length);
#sql {CALL STORPROC(:IN asciiStream)};
For these calls, you need to specify the exact length of the input data. You
cannot use this technique for input/output parameters.
v Use a java.lang.String input parameter:
java.lang.String charData;
#sql {CALL STORPROC(:IN charData)};
Output parameters for CLOB columns
For output or input/output parameters for CLOB columns, you can use one of the
following techniques:
v Use a java.sql.Clob output variable, which is an exact match for a CLOB column:
java.sql.Clob clobData = null;
#sql CALL STORPROC(:OUT clobData)};
v Use a java.lang.String output variable:
java.lang.String charData = null;
#sql CALL STORPROC(:OUT charData)};
138 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