使用Groovy连接到MySQL

时间:2016-08-13 19:22:35

标签: mysql groovy soapui

我尝试使用MAC OS 10.10.5 Yosemite上的以下Groovy代码连接到MySQL数据库

import groovy.sql.Sql

try{
    def dbURL = 'jdbc:mysql://localhost:3306/sakila'
    def dbUserName = 'root'
    def dbPassword = 'Orange@27'
    def dbDriver = 'com.mysql.jdbc.Driver'
    log.info('Good')
    def db = Sql.newInstance(dbURL,dbUserName,dbPassword,dbDriver)
}catch(Exception e){
    log.info('DB Error')
    log.info(e.getMessage())
}finally{

}

但是当我执行此代码时,我会看到以下消息

Sat Aug 13 15:09:14 EDT 2016:INFO:Good
Sat Aug 13 15:09:14 EDT 2016:INFO:DB Error
Sat Aug 13 15:09:14 EDT 2016:INFO:No suitable driver found for jdbc:mysql://localhost:3306/sakila

我已将groovy-sql-2.1.1.jarmysql-connector-java-5.1.39-bin.jar保留在文件夹位置/Applications/SoapUI-5.2.1/bin/ext/

你能帮我解决一下这个问题吗?

1 个答案:

答案 0 :(得分:1)

  • 应该在SOAPUI_HOME / bin / ext目录下复制用户库,在这种情况下,复制上面目录中的mysql jdbc库。
  • SoapUI以不同方式注册jdbc驱动程序。使用以下语句按照documentation注册:
//Register driver
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver( "com.mysql.jdbc.Driver")
//Get the sql instance using the connection details.
Sql.newInstance(dbURL,dbUserName,dbPassword)