soapUI access MS SQL DB from groovy script

此生再无相见时 提交于 2019-12-05 15:41:28
kumar

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.

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.

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")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!