Forum Discussion

venkee_rb's avatar
venkee_rb
New Contributor
7 years ago

how to access jdbc connection string set at environment level?

Hello,   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 ...
  • Radford's avatar
    7 years ago

    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) } log.info 'JDBC Name = ' + jdbcConnection.getName() log.info '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:

     

    import com.eviware.soapui.support.GroovyUtilsPro
    
    def groovyUtilsPro = new  GroovyUtilsPro(context)
    def sql = groovyUtilsPro.getGroovySql('testdb')