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