Groovy:RedHat:java.sql.SQLException:未找到适合jdbc:mysql的驱动程序:
我尝试在rhshell下执行groovy脚本 [localhost]groovy/home/rualas4/script.groovy 但收到了例外Groovy:RedHat:java.sql.SQLException:未找到适合jdbc:mysql的驱动程序:,mysql,jdbc,groovy,driver,redhat,Mysql,Jdbc,Groovy,Driver,Redhat,我尝试在rhshell下执行groovy脚本 [localhost]groovy/home/rualas4/script.groovy 但收到了例外 Caught: java.sql.SQLException: No suitable driver found for jdbc:mysql:/localhost:3306/ java.sql.SQLException: No suitable driver found for jdbc:mysql:/localhost:3306/
Caught: java.sql.SQLException: No suitable driver found for jdbc:mysql:/localhost:3306/
java.sql.SQLException: No suitable driver found for jdbc:mysql:/localhost:3306/
at script.run(script.groovy:13)
我已经安装了下一个软件包:
unixODBC-2.2.14-12.el6_3.x86_64
mysql-connector-odbc-5.3.2-1.el6.x86_64
我的代码是:
@GrabConfig(systemClassLoader = true)
@Grab(group='mysql', module='mysql-connector-java', version='5.1.25')
import groovy.sql.Sql
import groovy.io.FileType
println "Initialize connection"
url="jdbc:mysql://localhost:3306/"
username = "test"
password = "test"
driver = "com.mysql.jdbc.Driver"
sql = Sql.newInstance(url, username, password, driver)
我的groovy/opt/groovy/lib目录中还有mysql-connector-java-5.1.25-bin.jar
请提供解决错误异常的解决方案当com.mysql.jdbc.Driver解析您的url查找jdbc:mysql://时,您的连接url中缺少一个/字符:
Caught: java.sql.SQLException: No suitable driver found for jdbc:mysql:/localhost:3306/
java.sql.SQLException: No suitable driver found for jdbc:mysql:/localhost:3306/
at script.run(script.groovy:13)
com.mysql.jdbc.Driver类:
com.mysql.jdbc.NonRegisteringDriver类:
因此:
更改:
jdbc:mysql:/localhost:3306/
致:
jdbc:mysql://localhost:3306/
希望这有帮助,您能尝试将其从/opt/groovy/lib中删除吗?在同一个类路径上有两个相似的JAR从来都不是一件好事URL中没有错误吗?不应该是:jdbc:mysql://10.242.182.152:3306/? DB_NAME也丢失了?@Opal:在我的代码中,我使用的语法如下:sql.eachRowSELECT*FROM+NAME+.TABLE,其中COLUMN='VALUE'NAME是数据库的名称。我的程序在Windows下工作,但不是在RH下。@tim_yates:我从/opt/groovy/lib dir中删除了mysql-connector-java-5.1.25-bin.jar,当我执行脚本时,它会在控制台中冻结。。我看不到脚本运行的结果,唯一能中断脚本执行的方法是CTL+CStill在ExecuteEyes之后冻结。我尝试删除此文件并再次添加。这没用。
package com.mysql.jdbc;
import java.sql.SQLException;
public class NonRegisteringDriver implements java.sql.Driver {
...
private static final String URL_PREFIX = "jdbc:mysql://";
...
public Properties parseURL(String url, Properties defaults)
throws java.sql.SQLException {
Properties urlProps = (defaults != null) ? new Properties(defaults)
: new Properties();
if (url == null) {
return null;
}
if (!StringUtils.startsWithIgnoreCase(url, URL_PREFIX)
&& !StringUtils.startsWithIgnoreCase(url, MXJ_URL_PREFIX)
&& !StringUtils.startsWithIgnoreCase(url,
LOADBALANCE_URL_PREFIX)
&& !StringUtils.startsWithIgnoreCase(url,
REPLICATION_URL_PREFIX)) {
return null;
}
...
}