Search in sources :

Example 86 with CallableStatement

use of java.sql.CallableStatement in project ats-framework by Axway.

the class DbWriteAccess method startSuite.

public int startSuite(String packageName, String suiteName, long timestamp, int runId, boolean closeConnection) throws DatabaseAccessException {
    final String errMsg = "Unable to start suite with name " + suiteName;
    // create a new suite
    CallableStatement callableStatement = null;
    try {
        refreshInternalConnection();
        // TODO : remove me after 3.6.0
        String dbVersionString = getDatabaseVersion();
        int dbVersion = Integer.parseInt(dbVersionString.replace(".", ""));
        if (dbVersion >= 350) {
            callableStatement = connection.prepareCall("{ call sp_start_suite(?, ?, ?, ?, ?, ?) }");
            if (packageName == null) {
                packageName = "";
            }
            callableStatement.setString("@package", packageName);
        } else {
            callableStatement = connection.prepareCall("{ call sp_start_suite(?, ?, ?, ?, ?) }");
        }
        callableStatement.setString("@suiteName", suiteName);
        callableStatement.setInt("@runId", runId);
        callableStatement.setTimestamp("@dateStart", new Timestamp(timestamp));
        callableStatement.registerOutParameter("@RowsInserted", Types.INTEGER);
        callableStatement.registerOutParameter("@suiteId", Types.INTEGER);
        callableStatement.execute();
        if (callableStatement.getInt("@RowsInserted") != 1) {
            throw new DatabaseAccessException(errMsg);
        } else {
            if (callableStatement.getInt("@suiteId") == 0) {
                throw new DatabaseAccessException(errMsg + " - suite ID returned was 0");
            }
        }
        // get the result
        return callableStatement.getInt("@suiteId");
    } catch (Exception e) {
        throw new DatabaseAccessException(errMsg, e);
    } finally {
        if (closeConnection) {
            DbUtils.close(connection, callableStatement);
        } else {
            DbUtils.closeStatement(callableStatement);
        }
    }
}
Also used : CallableStatement(java.sql.CallableStatement) Timestamp(java.sql.Timestamp) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) SQLException(java.sql.SQLException)

Example 87 with CallableStatement

use of java.sql.CallableStatement in project jdbc-shards by wplatform.

the class BatchUpdatesTestCase method testExecuteCall.

private void testExecuteCall() throws SQLException {
    conn = getConnection();
    stat = conn.createStatement();
    stat.execute("CREATE ALIAS updatePrices FOR \"" + getClass().getName() + ".updatePrices\"");
    CallableStatement call = conn.prepareCall("{call updatePrices(?, ?)}");
    call.setString(1, "Hello");
    call.setFloat(2, 1.4f);
    call.addBatch();
    call.setString(1, "World");
    call.setFloat(2, 3.2f);
    call.addBatch();
    int[] updateCounts = call.executeBatch();
    int total = 0;
    for (int t : updateCounts) {
        total += t;
    }
    assertEquals(4, total);
    conn.close();
}
Also used : CallableStatement(java.sql.CallableStatement)

Example 88 with CallableStatement

use of java.sql.CallableStatement in project jdbc-shards by wplatform.

the class CallableStatementTestCase method testCallWithResultSet.

private void testCallWithResultSet(Connection conn) throws SQLException {
    CallableStatement call;
    ResultSet rs;
    call = conn.prepareCall("select 10 as a");
    call.execute();
    rs = call.getResultSet();
    rs.next();
    assertEquals(10, rs.getInt(1));
}
Also used : CallableStatement(java.sql.CallableStatement) SimpleResultSet(com.wplatform.ddal.result.SimpleResultSet) ResultSet(java.sql.ResultSet)

Example 89 with CallableStatement

use of java.sql.CallableStatement in project jdbc-shards by wplatform.

the class CallableStatementTestCase method testCallWithResult.

private void testCallWithResult(Connection conn) throws SQLException {
    CallableStatement call;
    for (String s : new String[] { "{?= call abs(?)}", " { ? = call abs(?)}", " {? = call abs(?)}" }) {
        call = conn.prepareCall(s);
        call.setInt(2, -3);
        call.registerOutParameter(1, Types.INTEGER);
        call.execute();
        assertEquals(3, call.getInt(1));
        call.executeUpdate();
        assertEquals(3, call.getInt(1));
    }
}
Also used : CallableStatement(java.sql.CallableStatement)

Example 90 with CallableStatement

use of java.sql.CallableStatement in project jdbc-shards by wplatform.

the class CallableStatementTestCase method testUnsupportedOperations.

private void testUnsupportedOperations(Connection conn) throws SQLException {
    CallableStatement call;
    call = conn.prepareCall("select 10 as a");
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getURL(1);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getObject(1, Collections.<String, Class<?>>emptyMap());
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRef(1);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRowId(1);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getSQLXML(1);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getURL("a");
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getObject("a", Collections.<String, Class<?>>emptyMap());
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRef("a");
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getRowId("a");
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).getSQLXML("a");
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setURL(1, (URL) null);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRef(1, (Ref) null);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRowId(1, (RowId) null);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setSQLXML(1, (SQLXML) null);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setURL("a", (URL) null);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setRowId("a", (RowId) null);
    assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, call).setSQLXML("a", (SQLXML) null);
}
Also used : 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