Forum Discussion

Bob_K's avatar
Bob_K
Occasional Contributor
16 years ago

I need help retrieving data from SQL Server in groovy script

In my test case I'm making a request that creates a number of database records,  I'm trying to add a groovy script step that will retrieve one of the db records.  I've stripped my script down to a bare minimum to test the connection but I still get an error.  I'm using sql server 2005 for the db.

import groovy.sql.Sql

def sql = Sql.newInstance("jdbc:sqlserver://99.999.999.99",  "dbuserid", "dbpass", "com.microsoft.sqlserver.jdbc.SQLServerDriver")

sql.eachRow("select first_name from myTable")


I'm getting this error:
groovy.lang.MissingMethodException: No signature of method: groovy.sql.Sql.eachRow() is applicable for argument types: (java.lang.String) values: {"select first_name from myTable"}

2 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    You need to pass a closure to the eachRow method (specifying what to do for each row). Try it with an empty closure.

    You should also take a look at soapUI Pro, which has the DataSource Step for connecting to a database.

    Good Luck!
    /Nenad
    http://eviware.com
  • Bob_K's avatar
    Bob_K
    Occasional Contributor
    I added the closure and that fixed it, thanks.

    I did try soapUI Pro and sent a purchase request to my manager but in the mean time my trial period ended. I'm trying to replace my DataSource steps with groovy scripts to get the test scripts running again.