IBM DB2 Manual page 154

Table of Contents

Advertisement

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:
v Use one of the following types of stream input parameters:
v Use a java.lang.String input parameter:
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:
v Use a java.lang.String output variable:
138
Application Programming Guide and Reference for Java
#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);
– A sqlj.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)};
– A sqlj.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)};
– A sqlj.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.
java.lang.String charData;
#sql {CALL STORPROC(:IN charData)};
java.sql.Clob clobData = null;
#sql CALL STORPROC(:OUT clobData)};
java.lang.String charData = null;
#sql CALL STORPROC(:OUT charData)};

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents