Search in sources :

Example 91 with Statement

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();
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 92 with Statement

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();
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 93 with Statement

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();
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 94 with Statement

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();
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet)

Example 95 with Statement

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");
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Timestamp(java.sql.Timestamp) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Statement (java.sql.Statement)3054 Connection (java.sql.Connection)1634 ResultSet (java.sql.ResultSet)1631 SQLException (java.sql.SQLException)1529 PreparedStatement (java.sql.PreparedStatement)1329 Test (org.junit.Test)570 ArrayList (java.util.ArrayList)323 CallableStatement (java.sql.CallableStatement)135 ResultSetMetaData (java.sql.ResultSetMetaData)127 IOException (java.io.IOException)121 Properties (java.util.Properties)114 HashMap (java.util.HashMap)83 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)81 DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)71 StringPlus (mom.trd.opentheso.bdd.tools.StringPlus)63 DataSource (javax.sql.DataSource)62 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)61 Vector (java.util.Vector)61 DatabaseMetaData (java.sql.DatabaseMetaData)53 KeyValue (org.vcell.util.document.KeyValue)49