Forum Discussion
robjahn
12 years agoContributor
Just to share a bit to others this is what came up with:
import groovy.sql.Sql;
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver( "oracle.jdbc.driver.OracleDriver");
// determine environment connection information
// activeEnvironment will not work if in the default environment
def jdbcConnection='MUP'
if (testRunner.testCase.testSuite.project.activeEnvironment.name=='Default')
Myconnection = testRunner.testCase.testSuite.project.databaseConnectionContainer.getDatabaseConnectionByName(jdbcConnection)
else
Myconnection = testRunner.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(jdbcConnection)
// this is for debugging purpose
log.info 'activeEnvironment value is:' + testRunner.testCase.testSuite.project.activeEnvironment.name;
log.info 'Active Connection String is:' + Myconnection.getConnectionString()
// try to open the connection
try {
def connection= Sql.newInstance(Myconnection.getConnectionString(),"oracle.jdbc.driver.OracleDriver");
context.setProperty("dbConn", connection);
}
catch (Exception e) {
log.error "Could not establish connection to the database.";
assert false,"Could not establish connection to the database.";
}
if (context.dbConn) {
def sql = "select 1 from dual";
def status= context.dbConn.execute(sql);
if (status==false)
{
log.error "There was an error running SQL: " + sql
}
context.dbConn.close();
}
import groovy.sql.Sql;
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver( "oracle.jdbc.driver.OracleDriver");
// determine environment connection information
// activeEnvironment will not work if in the default environment
def jdbcConnection='MUP'
if (testRunner.testCase.testSuite.project.activeEnvironment.name=='Default')
Myconnection = testRunner.testCase.testSuite.project.databaseConnectionContainer.getDatabaseConnectionByName(jdbcConnection)
else
Myconnection = testRunner.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(jdbcConnection)
// this is for debugging purpose
log.info 'activeEnvironment value is:' + testRunner.testCase.testSuite.project.activeEnvironment.name;
log.info 'Active Connection String is:' + Myconnection.getConnectionString()
// try to open the connection
try {
def connection= Sql.newInstance(Myconnection.getConnectionString(),"oracle.jdbc.driver.OracleDriver");
context.setProperty("dbConn", connection);
}
catch (Exception e) {
log.error "Could not establish connection to the database.";
assert false,"Could not establish connection to the database.";
}
if (context.dbConn) {
def sql = "select 1 from dual";
def status= context.dbConn.execute(sql);
if (status==false)
{
log.error "There was an error running SQL: " + sql
}
context.dbConn.close();
}
Related Content
- 4 years agoTommyTester
Recent Discussions
- 25 minutes agoLukaszK