01: /*
02: * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
03: * (license2)
04: * Initial Developer: H2 Group
05: */
06: package org.h2.test.jdbc;
07:
08: import java.sql.CallableStatement;
09: import java.sql.Connection;
10: import java.sql.ResultSet;
11: import java.sql.Statement;
12:
13: import org.h2.test.TestBase;
14:
15: /**
16: * Tests for the CallableStatement class.
17: */
18: public class TestCallableStatement extends TestBase {
19:
20: public void test() throws Exception {
21: deleteDb("callableStatement");
22: Connection conn = getConnection("preparedStatement");
23: testPrepare(conn);
24: conn.close();
25: }
26:
27: private void testPrepare(Connection conn) throws Exception {
28: Statement stat = conn.createStatement();
29: CallableStatement call;
30: ResultSet rs;
31: stat.execute("CREATE TABLE TEST(ID INT, NAME VARCHAR)");
32: call = conn.prepareCall("INSERT INTO TEST VALUES(?, ?)");
33: call.setInt(1, 1);
34: call.setString(2, "Hello");
35: call.execute();
36: call = conn
37: .prepareCall("SELECT * FROM TEST",
38: ResultSet.TYPE_FORWARD_ONLY,
39: ResultSet.CONCUR_READ_ONLY);
40: rs = call.executeQuery();
41: rs.next();
42: check(1, rs.getInt(1));
43: check("Hello", rs.getString(2));
44: checkFalse(rs.next());
45: call = conn.prepareCall("SELECT * FROM TEST",
46: ResultSet.TYPE_FORWARD_ONLY,
47: ResultSet.CONCUR_READ_ONLY,
48: ResultSet.HOLD_CURSORS_OVER_COMMIT);
49: rs = call.executeQuery();
50: rs.next();
51: check(1, rs.getInt(1));
52: check("Hello", rs.getString(2));
53: checkFalse(rs.next());
54: }
55:
56: }
|