soapUI access MS SQL DB from groovy script

可紊 提交于 2019-12-07 08:25:21

问题


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")


来源:https://stackoverflow.com/questions/4791680/soapui-access-ms-sql-db-from-groovy-script

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