use of org.h2.jdbc.JdbcStatement in project h2database by h2database.
the class JdbcConnection method createStatement.
/**
* Creates a new statement.
*
* @return the new statement
* @throws SQLException if the connection is closed
*/
@Override
public Statement createStatement() throws SQLException {
try {
int id = getNextId(TraceObject.STATEMENT);
if (isDebugEnabled()) {
debugCodeAssign("Statement", TraceObject.STATEMENT, id, "createStatement()");
}
checkClosed();
return new JdbcStatement(this, id, ResultSet.TYPE_FORWARD_ONLY, Constants.DEFAULT_RESULT_SET_CONCURRENCY, false);
} catch (Exception e) {
throw logAndConvert(e);
}
}
use of org.h2.jdbc.JdbcStatement in project h2database by h2database.
the class TestGetGeneratedKeys method testStatementExecuteLargeUpdate_int.
/**
* Test method for {@link Statement#executeLargeUpdate(String, int)}.
*
* @param conn
* connection
* @throws Exception
* on exception
*/
private void testStatementExecuteLargeUpdate_int(Connection conn) throws Exception {
JdbcStatement stat = (JdbcStatement) conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL, OTHER INT DEFAULT 0)");
stat.executeLargeUpdate("INSERT INTO TEST(VALUE) VALUES (10)", Statement.NO_GENERATED_KEYS);
ResultSet rs = stat.getGeneratedKeys();
assertFalse(rs.next());
rs.close();
stat.executeLargeUpdate("INSERT INTO TEST(VALUE) VALUES (20)", Statement.RETURN_GENERATED_KEYS);
rs = stat.getGeneratedKeys();
assertEquals(2, rs.getMetaData().getColumnCount());
assertEquals("ID", rs.getMetaData().getColumnName(1));
assertEquals("UID", rs.getMetaData().getColumnName(2));
assertTrue(rs.next());
assertEquals(2L, rs.getLong(1));
assertEquals(UUID.class, rs.getObject(2).getClass());
assertFalse(rs.next());
rs.close();
stat.execute("DROP TABLE TEST");
}
use of org.h2.jdbc.JdbcStatement in project h2database by h2database.
the class TestGetGeneratedKeys method testStatementExecuteLargeUpdate.
/**
* Test method for {@link Statement#executeLargeUpdate(String)}.
*
* @param conn
* connection
* @throws Exception
* on exception
*/
private void testStatementExecuteLargeUpdate(Connection conn) throws Exception {
JdbcStatement stat = (JdbcStatement) conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)");
stat.executeLargeUpdate("INSERT INTO TEST(VALUE) VALUES (10)");
ResultSet rs = stat.getGeneratedKeys();
assertFalse(rs.next());
rs.close();
stat.execute("DROP TABLE TEST");
}
use of org.h2.jdbc.JdbcStatement in project h2database by h2database.
the class TestGetGeneratedKeys method testStatementExecuteLargeUpdate_intArray.
/**
* Test method for {@link Statement#executeLargeUpdate(String, int[])}.
*
* @param conn
* connection
* @throws Exception
* on exception
*/
private void testStatementExecuteLargeUpdate_intArray(Connection conn) throws Exception {
JdbcStatement stat = (JdbcStatement) conn.createStatement();
stat.execute("CREATE TABLE TEST (ID BIGINT PRIMARY KEY AUTO_INCREMENT," + "UID UUID NOT NULL DEFAULT RANDOM_UUID(), VALUE INT NOT NULL)");
stat.executeLargeUpdate("INSERT INTO TEST(VALUE) VALUES (10)", new int[0]);
ResultSet rs = stat.getGeneratedKeys();
assertFalse(rs.next());
rs.close();
stat.executeLargeUpdate("INSERT INTO TEST(VALUE) VALUES (20)", new int[] { 1, 2 });
rs = stat.getGeneratedKeys();
assertEquals(2, rs.getMetaData().getColumnCount());
assertEquals("ID", rs.getMetaData().getColumnName(1));
assertEquals("UID", rs.getMetaData().getColumnName(2));
assertTrue(rs.next());
assertEquals(2L, rs.getLong(1));
assertEquals(UUID.class, rs.getObject(2).getClass());
assertFalse(rs.next());
rs.close();
stat.executeLargeUpdate("INSERT INTO TEST(VALUE) VALUES (30)", new int[] { 2, 1 });
rs = stat.getGeneratedKeys();
assertEquals(2, rs.getMetaData().getColumnCount());
assertEquals("UID", rs.getMetaData().getColumnName(1));
assertEquals("ID", rs.getMetaData().getColumnName(2));
assertTrue(rs.next());
assertEquals(UUID.class, rs.getObject(1).getClass());
assertEquals(3L, rs.getLong(2));
assertFalse(rs.next());
rs.close();
stat.executeLargeUpdate("INSERT INTO TEST(VALUE) VALUES (40)", new int[] { 2 });
rs = stat.getGeneratedKeys();
assertEquals(1, rs.getMetaData().getColumnCount());
assertEquals("UID", rs.getMetaData().getColumnName(1));
assertTrue(rs.next());
assertEquals(UUID.class, rs.getObject(1).getClass());
assertFalse(rs.next());
rs.close();
stat.execute("DROP TABLE TEST");
}
Aggregations