sqlSelect = "SELECT ID_VAL FROM ID_GEN WHERE ID_NAME='SERVICE_INSTANCE_ID'";
try {
stmtUpdate = conn.prepareStatement(sqlUpdate);
} catch (SQLException e) {
throw new ConsoleEngineRuntimeException("Impossible to create a prepared statement for query [" + sqlUpdate + "]", e);
}
logger.debug("Statement [" + stmtUpdate.toString() + "] has been succesfully created");
try {
stmtUpdate.executeUpdate();
} catch (SQLException e) {
throw new ConsoleEngineRuntimeException("Impossible to execute statement [" + stmtUpdate.toString() + "]", e);
}
logger.debug("Statement [" + stmtUpdate.toString() + "] has been succesfully executed");
try {
stmtSelect = conn.prepareStatement(sqlSelect);
} catch (SQLException e) {
throw new ConsoleEngineRuntimeException("Impossible to create a prepared statement for query [" + sqlUpdate + "]", e);
}
logger.debug("Statement [" + stmtSelect.toString() + "] has been succesfully created");
try {
stmtSelect.execute();
} catch (SQLException e) {
throw new ConsoleEngineRuntimeException("Impossible to execute statement [" + stmtSelect.toString() + "]", e);
}
logger.debug("Statement [" + stmtSelect.toString() + "] has been succesfully executed");
resultSet = stmtSelect.getResultSet();
Assert.assertTrue(resultSet.getMetaData().getColumnCount() > 0, "The query [" + stmtSelect.toString()+ "] returned a multicolumn resultset");
if(resultSet.next()) {
idServiceInstance = new Double( resultSet.getDouble(1) );
} else {
Assert.assertUnreachable("The query [" + stmtSelect.toString()+ "] returned no results");
}
Assert.assertTrue(!resultSet.next(), "The query [" + stmtSelect.toString()+ "] returned more than one record");
conn.commit();
} catch(Throwable t ) {
throw new ConsoleEngineRuntimeException("Impossible to get resource id", t);
} finally {
releaseResources(null, stmtUpdate, null);
releaseResources(null, stmtSelect, resultSet);
logger.debug("OUT");
}