}
}
private void testPrepare(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
CallableStatement call;
ResultSet rs;
stat.execute("CREATE TABLE TEST(ID INT, NAME VARCHAR)");
call = conn.prepareCall("INSERT INTO TEST VALUES(?, ?)");
call.setInt(1, 1);
call.setString(2, "Hello");
call.execute();
call = conn.prepareCall("SELECT * FROM TEST",
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
rs = call.executeQuery();
rs.next();
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
call = conn.prepareCall("SELECT * FROM TEST",
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY,
ResultSet.HOLD_CURSORS_OVER_COMMIT);
rs = call.executeQuery();
rs.next();
assertEquals(1, rs.getInt(1));
assertEquals("Hello", rs.getString(2));
assertFalse(rs.next());
stat.execute("CREATE ALIAS testCall FOR \"" + getClass().getName() + ".testCall\"");
call = conn.prepareCall("{CALL testCall(?,?,?)}");
call.setInt("A", 100);
call.setString(2, "abc");
long t = System.currentTimeMillis();
call.setTimestamp("C", new Timestamp(t));
call.registerOutParameter(1, Types.INTEGER);
call.registerOutParameter("B", Types.VARCHAR);
call.executeUpdate();
try {
call.getTimestamp("C");
fail("not registered out parameter accessible");
} catch (SQLException e) {
// expected exception
}
call.registerOutParameter(3, Types.TIMESTAMP);
call.executeUpdate();
assertEquals(t + 1, call.getTimestamp(3).getTime());
assertEquals(200, call.getInt("A"));
assertEquals("ABC", call.getString("B"));
try {
call.getString(100);
fail("incorrect parameter index value");
} catch (SQLException e) {
// expected exception
}
try {
call.getString(0);
fail("incorrect parameter index value");
} catch (SQLException e) {
// expected exception
}
try {
call.getBoolean("X");
fail("incorrect parameter name value");
} catch (SQLException e) {
// expected exception
}
// test for exceptions after closing
call.close();
assertThrows(ErrorCode.OBJECT_CLOSED, call).
executeUpdate();
assertThrows(ErrorCode.OBJECT_CLOSED, call).
registerOutParameter(1, Types.INTEGER);
assertThrows(ErrorCode.OBJECT_CLOSED, call).