soapUI access MS SQL DB from groovy script

2019-05-03 12:20发布

问题:

I am trying to connect to MS Sql 2005 DB from SoapUI using Groovy script.

import groovy.sql.Sql

sql = Sql.newInstance("jdbc:jtds:sqlserver://servername\\inst1/databaseName", 
     "username", "password", "com.microsoft.sqlserver.jdbc.SQLServerDriver")

Error: No suitable driver found for jdbc:jtds:sqlserver://32esx802\inst1/tlMain

I have tried to use "net.sourceforge.jtds.jdbc.Driver" but i still get the same error

Please let me know what i am doing wrong.

Thanks

回答1:

Found the answer

first remove "jtds" from the connect string, so the syntax will look like

sql = Sql.newInstance("jdbc:sqlserver://servername\\inst1/databaseName", 
     "username", "password", "com.microsoft.sqlserver.jdbc.SQLServerDriver")

Once this is fixed another error came up. I got a timeout error. Based on the original post there seems to be some weird conflict between Groovy sql and MS sql. to work around this remove the databaseName and the database reference in the sql statement. So the sql syntax will look like.

import groovy.sql.Sql
sql = Sql.newInstance("jdbc:sqlserver://servername\\inst1", 
     "username", "password", "com.microsoft.sqlserver.jdbc.SQLServerDriver")

def row = sql.firstRow("select te.tDisplayName from dbName.TableName te where te.Column2=5000006")

log.info(row.tDisplayName);

also if you have error stating that could not find com.microsoft.sqlserver.jdbc.SQLServerDriver make sure you download sqljdbc.jar from Microsoft site and place it in C:\Program Files\eviware\soapUI-3.6.1\lib and restart SoapUI.



回答2:

I had the same problem and looks like I am getting closed. I did everything as stated above but getting following exception- java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.6 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.



回答3:

Try Adding the following lines to the beginning of your script.

// Registering JDBC Driver
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver")