Search in sources :

Example 51 with Statement

use of java.sql.Statement in project hive by apache.

the class TestJdbcWithMiniLlap method createTestTable.

private void createTestTable(String tableName) throws Exception {
    Statement stmt = hs2Conn.createStatement();
    // create table
    stmt.execute("DROP TABLE IF EXISTS " + tableName);
    stmt.execute("CREATE TABLE " + tableName + " (under_col INT COMMENT 'the under column', value STRING) COMMENT ' test table'");
    // load data
    stmt.execute("load data local inpath '" + kvDataFilePath.toString() + "' into table " + tableName);
    ResultSet res = stmt.executeQuery("SELECT * FROM " + tableName);
    assertTrue(res.next());
    assertEquals("val_238", res.getString(2));
    res.close();
    stmt.close();
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet)

Example 52 with Statement

use of java.sql.Statement in project hive by apache.

the class TestMultiSessionsHS2WithLocalClusterSpark method createConnection.

private void createConnection() throws Exception {
    Connection connection = DriverManager.getConnection(miniHS2.getJdbcURL(dbName), System.getProperty("user.name"), "bar");
    Statement statement = connection.createStatement();
    localConnection.set(connection);
    localStatement.set(statement);
    statement.execute("USE " + dbName);
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection)

Example 53 with Statement

use of java.sql.Statement in project hive by apache.

the class TestJdbcDriver2 method testShowTables.

@Test
public void testShowTables() throws SQLException {
    Statement stmt = con.createStatement();
    assertNotNull("Statement is null", stmt);
    ResultSet res = stmt.executeQuery("show tables");
    boolean testTableExists = false;
    while (res.next()) {
        assertNotNull("table name is null in result set", res.getString(1));
        if (tableName.equalsIgnoreCase(res.getString(1))) {
            testTableExists = true;
        }
    }
    assertTrue("table name " + tableName + " not found in SHOW TABLES result set", testTableExists);
    stmt.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 54 with Statement

use of java.sql.Statement in project hive by apache.

the class TestJdbcDriver2 method testNullResultSet.

@Test
public void testNullResultSet() throws Exception {
    List<String> setupQueries = new ArrayList<String>();
    String testQuery;
    Statement stmt = con.createStatement();
    // -select- should return a ResultSet
    testQuery = "select * from " + tableName + " limit 5";
    checkResultSetExpected(stmt, setupQueries, testQuery, true);
    setupQueries.clear();
    // -create- should not return a ResultSet
    setupQueries.add("drop table test_t1");
    testQuery = "create table test_t1 (under_col int, value string)";
    checkResultSetExpected(stmt, setupQueries, testQuery, false);
    setupQueries.clear();
    // -create table as select- should not return a ResultSet
    setupQueries.add("drop table test_t1");
    testQuery = "create table test_t1 as select * from " + tableName + " limit 5";
    checkResultSetExpected(stmt, setupQueries, testQuery, false);
    setupQueries.clear();
    // -insert table as select- should not return a ResultSet
    setupQueries.add("drop table test_t1");
    setupQueries.add("create table test_t1 (under_col int, value string)");
    testQuery = "insert into table test_t1 select under_col, value from " + tableName + " limit 5";
    checkResultSetExpected(stmt, setupQueries, testQuery, false);
    setupQueries.clear();
    stmt.close();
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) String(java.lang.String) Test(org.junit.Test)

Example 55 with Statement

use of java.sql.Statement in project hive by apache.

the class TestJdbcDriver2 method setUpBeforeClass.

@SuppressWarnings("deprecation")
@BeforeClass
public static void setUpBeforeClass() throws SQLException, ClassNotFoundException {
    conf = new HiveConf(TestJdbcDriver2.class);
    dataFileDir = conf.get("test.data.files").replace('\\', '/').replace("c:", "");
    dataFilePath = new Path(dataFileDir, "kv1.txt");
    dataFileRowCount = 500;
    dataTypeDataFilePath = new Path(dataFileDir, "datatypes.txt");
    // Create test database and base tables once for all the test
    Class.forName(driverName);
    System.setProperty(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_LEVEL.varname, "verbose");
    System.setProperty(ConfVars.HIVEMAPREDMODE.varname, "nonstrict");
    System.setProperty(ConfVars.HIVE_AUTHORIZATION_MANAGER.varname, "org.apache.hadoop.hive.ql.security.authorization.DefaultHiveAuthorizationProvider");
    System.setProperty(ConfVars.HIVE_SERVER2_PARALLEL_OPS_IN_SESSION.varname, "false");
    con = getConnection(defaultDbName + ";create=true");
    Statement stmt = con.createStatement();
    assertNotNull("Statement is null", stmt);
    stmt.execute("set hive.support.concurrency = false");
    stmt.execute("drop database if exists " + testDbName + " cascade");
    stmt.execute("create database " + testDbName);
    stmt.execute("use " + testDbName);
    createTestTables(stmt, testDbName);
    stmt.close();
}
Also used : Path(org.apache.hadoop.fs.Path) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) HiveConf(org.apache.hadoop.hive.conf.HiveConf) BeforeClass(org.junit.BeforeClass)

Aggregations

Statement (java.sql.Statement)2195 Connection (java.sql.Connection)1082 ResultSet (java.sql.ResultSet)1081 PreparedStatement (java.sql.PreparedStatement)957 SQLException (java.sql.SQLException)911 Test (org.junit.Test)547 ArrayList (java.util.ArrayList)152 CallableStatement (java.sql.CallableStatement)128 ResultSetMetaData (java.sql.ResultSetMetaData)122 Properties (java.util.Properties)110 IOException (java.io.IOException)85 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)81 DruidPooledStatement (com.alibaba.druid.pool.DruidPooledStatement)71 DataSource (javax.sql.DataSource)62 HashMap (java.util.HashMap)61 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)56 DruidPooledConnection (com.alibaba.druid.pool.DruidPooledConnection)47 Context (javax.naming.Context)42 MockConnection (com.alibaba.druid.mock.MockConnection)41 DatabaseMetaData (java.sql.DatabaseMetaData)40