1.0

Table Of Contents
+ ExampleObj.class.getName() + "' language java");
stmt.execute("CREATE PROCEDURE myProc " + "(IN inParam1 VARCHAR(10),
"
+ " OUT outParam2 INTEGER, "
+ " INOUT example ExampleObjType, OUT count INTEGER)"
+ "LANGUAGE JAVA PARAMETER STYLE JAVA " + "READS SQL DATA "
+ "DYNAMIC RESULT SETS 2 " + "EXTERNAL NAME '"
+ ProcedureTest.class.getName() + ".myProc'");
stmt.execute("create table MyTable(x int not null, y int not null)");
stmt.execute("insert into MyTable values (1, 10), (2, 20), (3, 30),
(4, 40)");
CallableStatement callableStmt = cxn
.prepareCall("{CALL myProc('abc', ?, ?, ?) ON TABLE MyTable WHERE
x BETWEEN 5 AND 10}");
callableStmt.registerOutParameter(1, Types.INTEGER);
callableStmt.registerOutParameter(2, Types.JAVA_OBJECT);
callableStmt.registerOutParameter(3, Types.INTEGER);
callableStmt.setObject(2, new ExampleObj());
callableStmt.execute();
int outParam2 = callableStmt.getInt(1);
ExampleObj example = (ExampleObj)callableStmt.getObject(2);
assert example.getValue() == 100;
assert outParam2 == 200;
ResultSet thisResultSet;
boolean moreResults = true;
int cnt = 0;
int rowCount = 0;
do {
thisResultSet = callableStmt.getResultSet();
int colCnt = thisResultSet.getMetaData().getColumnCount();
if (cnt == 0) {
System.out.println("Result Set 1 starts");
while (thisResultSet.next()) {
for (int i = 1; i < colCnt + 1; i++) {
System.out.print(thisResultSet.getObject(i));
if (i == 1) {
System.out.print(',');
}
}
System.out.println();
rowCount++;
}
System.out.println("ResultSet 1 ends\n");
cnt++;
}
else {
thisResultSet.next();
System.out.println("ResultSet 2 starts");
for (int i = 1; i < colCnt + 1; i++) {
cnt = thisResultSet.getInt(1);
System.out.print(cnt);
System.out.println();
}
147
Using Data-Aware Stored Procedures