How to use a preconfigured Database connection in Groovy
- 9 years ago
I used environment parameters to do this in SOAP UI NG
import groovy.sql.Sql
import java.sql.SQLExceptiontry {
def testDbUser = testRunner.testCase.testSuite.project.getPropertyValue("dbusername")
def testDbPass = testRunner.testCase.testSuite.project.getPropertyValue("dbpassword")
def testDbHost = testRunner.testCase.testSuite.project.getPropertyValue("dbhost")
def testDbPort = testRunner.testCase.testSuite.project.getPropertyValue("dbport")
def testDbServ = testRunner.testCase.testSuite.project.getPropertyValue("dbservicename")
def db = [url:'jdbc:oracle:thin:@'+testDbHost+':'+testDbPort+'/'+testDbServ, user:testDbUser, password:testDbPass, driver:'oracle.jdbc.driver.OracleDriver']
def sql = Sql.newInstance(db.url, db.user, db.password, db.driver)
log.info("using connection " + testDbUser + " " + db.url)sql.execute ("some sql")
sql.execute ("commit")
log.info("mandate data removed...")
}
catch (SQLException e){
def tmp = e.getSQLState ()
log.error (tmp, e)
}