Ask a Question

how to access jdbc connection string set at environment level?

New Contributor

how to access jdbc connection string set at environment level?



currently, I am using the below to get the connection string in groovy.  This obtains the connection string from database container which is static across environments.  Instead of this I want to get the connection string from the JDBC Connections tab from the soapui environments.  Is there a way to do that?


 def ConObj = context.testCase.testSuite.project.databaseConnectionContainer.getResourceByName('testdb');
 def constring = ConObj.getConnectionString();
 def sql = Sql.newInstance(constring);

 sql.eachRow(<select statment>)

Super Contributor

You need to check to see if you are in the environment mode or not and if appropriate go via the Environment object, something like:


def jdbcConnectionName = 'testdb'

if (testRunner.testCase.testSuite.project.isEnvironmentMode()) { jdbcConnection = testRunner.testCase.testSuite.project.activeEnvironment.databaseConnectionContainer.getDatabaseConnectionByName(jdbcConnectionName) } else { jdbcConnection = testRunner.testCase.testSuite.project.databaseConnectionContainer.getDatabaseConnectionByName(jdbcConnectionName) } 'JDBC Name = ' + jdbcConnection.getName() 'JDBC Connection String = ' + jdbcConnection.getConnectionString()



Note, if you are just after a groovy.sql.Sql object I think you can use the following which I believe takes care of checking if you are in environment mode or not:



def groovyUtilsPro = new  GroovyUtilsPro(context)
def sql = groovyUtilsPro.getGroovySql('testdb')

Thanks for the reply.  This did help to address the issue.  The 'groovyUtilsPro.getGroovySql' works very well and indeed it takes care of checking the environment mode. 


The first option using Environment opject complains as below.  do we have to import a specific package or pass an object as argument instead of string?


groovy.lang.MissingMethodException: No signature of method: is applicable for argument types: (java.lang.String) values: [testDb] error at line: 3



Super Contributor

I've just double checked my code above, cutting and pasting the above (albeit changing the value of jdbcConnectionName to a valid name for my project) directly into a new empty Groovy Script test step and it works for me in both the default and environment mode.


I'm not sure why it doesn't work for you? I am using a older version of Ready API, version 1.7 so perhaps that might have an impact?


On the plus side, I'm glad the GroovyUtilsPro method work for you as I feel this is a simpler and neater solution.

Showing results for 
Search instead for 
Did you mean: