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();
}
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()));
}
}
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"));
}
}
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);
}
}
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;
}
Aggregations