use of java.sql.Statement in project jdbc-shards by wplatform.
the class MetaDataTestCase method testColumnLobMeta.
private void testColumnLobMeta() throws SQLException {
Connection conn = getConnection();
Statement stat = conn.createStatement();
stat.executeUpdate("CREATE TABLE t (blob BLOB, clob CLOB)");
stat.execute("INSERT INTO t VALUES('', '')");
ResultSet rs = stat.executeQuery("SELECT blob,clob FROM t");
ResultSetMetaData rsMeta = rs.getMetaData();
assertEquals("java.sql.Blob", rsMeta.getColumnClassName(1));
assertEquals("java.sql.Clob", rsMeta.getColumnClassName(2));
rs.next();
assertTrue(rs.getObject(1) instanceof java.sql.Blob);
assertTrue(rs.getObject(2) instanceof java.sql.Clob);
stat.executeUpdate("DROP TABLE t");
conn.close();
}
use of java.sql.Statement in project jdbc-shards by wplatform.
the class MetaDataTestCase method testColumnDefault.
private void testColumnDefault() throws SQLException {
Connection conn = getConnection();
DatabaseMetaData meta = conn.getMetaData();
ResultSet rs;
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(A INT, B INT DEFAULT NULL)");
rs = meta.getColumns(null, null, "TEST", null);
rs.next();
assertEquals("A", rs.getString("COLUMN_NAME"));
assertEquals(null, rs.getString("COLUMN_DEF"));
rs.next();
assertEquals("B", rs.getString("COLUMN_NAME"));
assertEquals("NULL", rs.getString("COLUMN_DEF"));
assertFalse(rs.next());
stat.execute("DROP TABLE TEST");
conn.close();
}
use of java.sql.Statement in project jdbc-shards by wplatform.
the class MetaDataTestCase method testColumnPrecision.
private void testColumnPrecision() throws SQLException {
Connection conn = getConnection();
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE ONE(X NUMBER(12,2), Y FLOAT)");
stat.execute("CREATE TABLE TWO AS SELECT * FROM ONE");
ResultSet rs;
ResultSetMetaData rsMeta;
rs = stat.executeQuery("SELECT * FROM ONE");
rsMeta = rs.getMetaData();
assertEquals(12, rsMeta.getPrecision(1));
assertEquals(17, rsMeta.getPrecision(2));
assertEquals(Types.DECIMAL, rsMeta.getColumnType(1));
assertEquals(Types.DOUBLE, rsMeta.getColumnType(2));
rs = stat.executeQuery("SELECT * FROM TWO");
rsMeta = rs.getMetaData();
assertEquals(12, rsMeta.getPrecision(1));
assertEquals(17, rsMeta.getPrecision(2));
assertEquals(Types.DECIMAL, rsMeta.getColumnType(1));
assertEquals(Types.DOUBLE, rsMeta.getColumnType(2));
stat.execute("DROP TABLE ONE, TWO");
conn.close();
}
use of java.sql.Statement in project jdbc-shards by wplatform.
the class MetaDataTestCase method testQueryStatistics.
private void testQueryStatistics() throws SQLException {
Connection conn = getConnection();
Statement stat = conn.createStatement();
stat.execute("create table test(id int primary key, name varchar) as " + "select x, space(1000) from system_range(1, 2000)");
ResultSet rs = stat.executeQuery("select * from INFORMATION_SCHEMA.QUERY_STATISTICS");
assertFalse(rs.next());
rs.close();
stat.execute("SET QUERY_STATISTICS TRUE");
int count = 100;
for (int i = 0; i < count; i++) {
stat.execute("select * from test limit 10");
}
// The "order by" makes the result set more stable on windows, where the
// timer resolution is not that great
rs = stat.executeQuery("select * from INFORMATION_SCHEMA.QUERY_STATISTICS " + "ORDER BY EXECUTION_COUNT desc");
assertTrue(rs.next());
assertEquals("select * from test limit 10", rs.getString("SQL_STATEMENT"));
assertEquals(count, rs.getInt("EXECUTION_COUNT"));
assertEquals(10 * count, rs.getInt("CUMULATIVE_ROW_COUNT"));
rs.close();
conn.close();
}
use of java.sql.Statement in project jdbc-shards by wplatform.
the class PreparedStatementTestCase method testCoalesce.
private static void testCoalesce(Connection conn) throws SQLException {
Statement stat = conn.createStatement();
stat.executeUpdate("create table test(tm timestamp)");
stat.executeUpdate("insert into test values(current_timestamp)");
PreparedStatement prep = conn.prepareStatement("update test set tm = coalesce(?,tm)");
prep.setTimestamp(1, new java.sql.Timestamp(System.currentTimeMillis()));
prep.executeUpdate();
stat.executeUpdate("drop table test");
}
Aggregations