Search in sources :

Example 66 with SQLException

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

the class TestCustomAuthentication method testCustomAuthentication.

@Test
public void testCustomAuthentication() throws Exception {
    String url = "jdbc:hive2://localhost:10000/default";
    Class.forName("org.apache.hive.jdbc.HiveDriver");
    try {
        DriverManager.getConnection(url, "wronguser", "pwd");
        Assert.fail("Expected Exception");
    } catch (SQLException e) {
        Assert.assertNotNull(e.getMessage());
        Assert.assertTrue(e.getMessage(), e.getMessage().contains("Peer indicated failure: Error validating the login"));
    }
    Connection connection = DriverManager.getConnection(url, "hiveuser", "hive");
    connection.close();
    System.out.println(">>> PASSED testCustomAuthentication");
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) Test(org.junit.Test)

Example 67 with SQLException

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

the class cbo_rp_TestJdbcDriver2 method testErrorDiag.

@Test
public void testErrorDiag() throws SQLException {
    Statement stmt = con.createStatement();
    // verify syntax error
    try {
        stmt.executeQuery("select from " + dataTypeTableName);
        fail("SQLException is expected");
    } catch (SQLException e) {
        assertEquals("42000", e.getSQLState());
    }
    // verify table not fuond error
    try {
        stmt.executeQuery("select * from nonTable");
        fail("SQLException is expected");
    } catch (SQLException e) {
        assertEquals("42S02", e.getSQLState());
    }
    // verify invalid column error
    try {
        stmt.executeQuery("select zzzz from " + dataTypeTableName);
        fail("SQLException is expected");
    } catch (SQLException e) {
        assertEquals("42000", e.getSQLState());
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Test(org.junit.Test)

Example 68 with SQLException

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

the class cbo_rp_TestJdbcDriver2 method testPostClose.

/**
   * Validate error on closed resultset
   * @throws SQLException
   */
@Test
public void testPostClose() throws SQLException {
    Statement stmt = con.createStatement();
    ResultSet res = stmt.executeQuery("select * from " + tableName);
    assertNotNull("ResultSet is null", res);
    res.close();
    try {
        res.getInt(1);
        fail("Expected SQLException");
    } catch (SQLException e) {
    }
    try {
        res.getMetaData();
        fail("Expected SQLException");
    } catch (SQLException e) {
    }
    try {
        res.setFetchSize(10);
        fail("Expected SQLException");
    } catch (SQLException e) {
    }
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 69 with SQLException

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

the class cbo_rp_TestJdbcDriver2 method doTestErrorCase.

private void doTestErrorCase(String sql, String expectedMessage, String expectedSQLState, int expectedErrorCode) throws SQLException {
    Statement stmt = con.createStatement();
    boolean exceptionFound = false;
    try {
        stmt.execute(sql);
    } catch (SQLException e) {
        assertTrue("Adequate error messaging not found for '" + sql + "': " + e.getMessage(), e.getMessage().contains(expectedMessage));
        assertEquals("Expected SQLState not found for '" + sql + "'", expectedSQLState, e.getSQLState());
        assertEquals("Expected error code not found for '" + sql + "'", expectedErrorCode, e.getErrorCode());
        exceptionFound = true;
    }
    assertNotNull("Exception should have been thrown for query: " + sql, exceptionFound);
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement)

Example 70 with SQLException

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

the class cbo_rp_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
    try {
        stmt.executeQuery("select * from " + tableName);
        System.out.println("select: success");
    } catch (SQLException e) {
        failWithExceptionMsg(e);
    }
    // -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;
    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;
    checkResultSetExpected(stmt, setupQueries, testQuery, false);
    setupQueries.clear();
    stmt.close();
}
Also used : SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

SQLException (java.sql.SQLException)6792 PreparedStatement (java.sql.PreparedStatement)3048 ResultSet (java.sql.ResultSet)2426 Connection (java.sql.Connection)1871 ArrayList (java.util.ArrayList)972 Test (org.junit.Test)873 Statement (java.sql.Statement)779 IOException (java.io.IOException)341 List (java.util.List)335 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)298 Properties (java.util.Properties)255 DatabaseException (net.jforum.exceptions.DatabaseException)249 HashMap (java.util.HashMap)232 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)184 Timestamp (java.sql.Timestamp)171 CallableStatement (java.sql.CallableStatement)165 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)160 DalHints (com.ctrip.platform.dal.dao.DalHints)159 Map (java.util.Map)125 Date (java.util.Date)123