SQLJ applications that run under the IBM® Data Server Driver for JDBC and SQLJ and connect to DB2® for Linux, UNIX, and Windows data sources can call stored procedures that have ARRAY parameters.
You can use java.sql.Array objects as IN, OUT, or INOUT parameters in a stored procedure.
For IN or INOUT parameters, use the DB2Connection.createArrayOf method (JDBC 3.0 or earlier) or the Connection.createArrayOf method (JDBC 4.0 or later) to create a java.sql.Array object.
You need to retrieve the array elements from the ResultSet using the getObject method.
CREATE TYPE PHONENUMBERS AS VARCHAR(10) ARRAY[5]
Call GET_EMP_DATA with the two parameters.
Connection con;
String type = "CHAR";
String [] contents = {"1234", "5678", "9101"};
…
com.ibm.db2.jcc.DB2Connection db2con = (com.ibm.db2.jcc.DB2Connection) con;
// Cast the Connection as a DB2Connection
// so you can use the
// DB2Connection.createArrayOf method
java.sql.Array inPhoneData = db2con.createArrayOf(type, contents);
java.sql.Array outPhoneData;
try {
#sql [db2con] {CALL GET_EMP_DATA(:IN inPhoneData, :OUT outPhoneData ) };
}
catch( SQLException e )
{
throw e;
}
ResultSet rs = outPhoneData.getResultSet();
while (rs.next()) {
String phoneNum = (String)rs.getObject(2); // Get phone number
System.out.println("Phone number = " + phoneNum);
}