Groovy - setPropertyValue for a value in a file and using it in the same script
Hi folks, I've been trying to read values from a CSV via a script and use them within the same script to login to a db. I've got the db login and SQL query running when hard coded the DB login details and not using this CSV file, however lots of different people will be using this script who all have different properties etc so i would like to make it dynamic rather than having to manually change it every time. Each person will have a csv file with 5 values in which this script will refer to. I'm quite new to this and here is what i have so far but i'm getting "groovy.lang.MissingPropertyException: No Such property: DBServer for class" The fileReader code i have is taken from another script i have which does work when referencing in a soap request, however i want to try do a similar thing but refer in the same groovy script import groovy.sql.Sql import java.sql.* com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver") context.fileReader = new BufferedReader(new FileReader("C:\\tmp\\GroovySQL.csv")) firstLine = context.fileReader.readLine() String[] propData = firstLine.split(",") testRunner.testCase.testSuite.project.setPropertyValue("DBServer",propData[0]) testRunner.testCase.testSuite.project.setPropertyValue("DBDatabase",propData[1]) testRunner.testCase.testSuite.project.setPropertyValue("DBPort",propData[2]) testRunner.testCase.testSuite.project.setPropertyValue("DBUser",propData[3]) testRunner.testCase.testSuite.project.setPropertyValue("Password",propData[4]) //Connect to the DB String db_server = "{$DBServer}" String db_database = "{$DBDatabase}" String db_port = "{$DBPort}" String db_user = "{$DBUser}" String db_password = "{$DBPassword}" String connectionUrl = "jdbc:sqlserver://" + db_server + ":" + db_port + ";database=" + db_database + ";user=" + db_user + ";password=" + db_password; sql = Sql.newInstance( connectionUrl, "com.microsoft.sqlserver.jdbc.SQLServerDriver") //Read data sql.eachRow('select USER_ID from SP085_USERS') { p -> log.info "First Name = ${p.USER_ID}" } sql.close() Any help would be appreciated!Solved3KViews0likes2Comments