Search in sources :

Example 56 with CallableStatement

use of java.sql.CallableStatement in project voltdb by VoltDB.

the class TestJDBCDriver method testLostConnection.

@Test
public void testLostConnection() throws SQLException, ClassNotFoundException {
    // Break the current connection and try to execute a procedure call.
    CallableStatement cs = conn.prepareCall("{call Oopsy(?)}");
    stopServer();
    cs.setLong(1, 99);
    try {
        cs.execute();
    } catch (SQLException e) {
        assertEquals(e.getSQLState(), SQLError.CONNECTION_FAILURE);
    }
    // Restore a working connection for any remaining tests
    startServer();
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) Test(org.junit.Test)

Example 57 with CallableStatement

use of java.sql.CallableStatement in project voltdb by VoltDB.

the class TestJDBCDriver method testBadProcedureName.

@Test
public void testBadProcedureName() throws SQLException {
    CallableStatement cs = conn.prepareCall("{call Oopsy(?)}");
    cs.setLong(1, 99);
    try {
        cs.execute();
    } catch (SQLException e) {
        // Since it's a GENERAL_ERROR we need to look for a string by pattern.
        assertEquals(e.getSQLState(), SQLError.GENERAL_ERROR);
        assertTrue(Pattern.matches(".*Procedure .* not found.*", e.getMessage()));
    }
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) Test(org.junit.Test)

Example 58 with CallableStatement

use of java.sql.CallableStatement in project voltdb by VoltDB.

the class TestJDBCDriver method testDoubleInsert.

@Test
public void testDoubleInsert() throws SQLException {
    // long i_id, long i_im_id, String i_name, double i_price, String i_data
    CallableStatement cs = conn.prepareCall("{call InsertA(?, ?)}");
    cs.setInt(1, 55);
    cs.setInt(2, 66);
    cs.execute();
    try {
        cs.setInt(1, 55);
        cs.setInt(2, 66);
        cs.execute();
    } catch (SQLException e) {
        // Since it's a GENERAL_ERROR we need to look for a string by pattern.
        assertEquals(e.getSQLState(), SQLError.GENERAL_ERROR);
        assertTrue(e.getMessage().contains("violation of constraint"));
    }
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) Test(org.junit.Test)

Example 59 with CallableStatement

use of java.sql.CallableStatement in project voltdb by VoltDB.

the class TestJDBCMultiConnection method testMultiDisconnect.

/*
     * Test that multiple client connections properly handle disconnection.
     */
@Test
public void testMultiDisconnect() throws Exception {
    class Tester {

        List<CallableStatement> m_callableStatements = new ArrayList<CallableStatement>();

        int m_value = 0;

        void makeStatements() throws SQLException {
            for (Connection connection : m_connections) {
                CallableStatement cs = connection.prepareCall("{call InsertA(?, ?)}");
                cs.setInt(1, m_value + 100);
                cs.setInt(2, m_value + 1000);
                m_value++;
                m_callableStatements.add(cs);
            }
        }

        void testStatements(int expectConnectionFailures) {
            if (expectConnectionFailures < 0) {
                expectConnectionFailures = m_callableStatements.size();
            }
            for (int i = 0; i < m_connections.length; ++i) {
                try {
                    m_callableStatements.get(i).execute();
                    assertEquals(0, expectConnectionFailures);
                } catch (SQLException e) {
                    assertTrue(expectConnectionFailures > 0);
                    expectConnectionFailures--;
                    assertEquals(e.getSQLState(), SQLError.CONNECTION_FAILURE);
                }
            }
        }
    }
    // Expect connection/query successes.
    {
        Tester tester = new Tester();
        tester.makeStatements();
        tester.testStatements(0);
    }
    // Shut down unceremoneously
    m_server.shutdown();
    // Expect connection failures.
    {
        Tester tester = new Tester();
        tester.makeStatements();
        tester.testStatements(-1);
    }
    // Restart server.
    startServer();
    // Expect connection/query successes.
    {
        Tester tester = new Tester();
        tester.makeStatements();
        tester.testStatements(0);
    }
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 60 with CallableStatement

use of java.sql.CallableStatement in project voltdb by VoltDB.

the class TestJDBCSecurityEnabled method execAdhocReadProc.

private boolean execAdhocReadProc() throws SQLException {
    CallableStatement stmt = myconn.prepareCall("{call @AdHoc(?) }");
    stmt.setString(1, "SELECT COUNT(*) FROM T;");
    try {
        stmt.execute();
    } catch (SQLException e) {
        return false;
    }
    return true;
}
Also used : SQLException(java.sql.SQLException) CallableStatement(java.sql.CallableStatement)

Aggregations

CallableStatement (java.sql.CallableStatement)273 SQLException (java.sql.SQLException)138 Connection (java.sql.Connection)125 ResultSet (java.sql.ResultSet)60 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)45 DbConnection (com.axway.ats.core.dbaccess.DbConnection)28 Checkpoint (com.axway.ats.log.autodb.entities.Checkpoint)22 ArrayList (java.util.ArrayList)22 PreparedStatement (java.sql.PreparedStatement)21 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)20 Timestamp (java.sql.Timestamp)18 Test (org.junit.Test)16 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)15 Statement (java.sql.Statement)14 HashMap (java.util.HashMap)10 CConnection (com.google.security.zynamics.binnavi.Database.CConnection)8 MockCallableStatement (com.alibaba.druid.mock.MockCallableStatement)7 MaybeNullException (com.google.security.zynamics.binnavi.Exceptions.MaybeNullException)6 BigInteger (java.math.BigInteger)6 OracleCallableStatement (oracle.jdbc.OracleCallableStatement)6