[英]MySQL connection JDBC driver not found
I am trying to open a MySQL connection but run into this error. 我正在尝试打开MySQL连接,但遇到此错误。
java.lang.ClassNotFoundException: com.mysql.jdbc.driver
There are plenty of questions online about this but I cannot seem to make it work. 网上有很多关于此的问题,但我似乎无法使它起作用。
I currently using gradle to compile 'com.oracle:ojdbc14:10.2.0.4.0'
and I have added the connector library using the build in maven importer. 我目前正在使用gradle来compile 'com.oracle:ojdbc14:10.2.0.4.0'
并且已经使用maven导入器中的构建添加了连接器库。
My code looks like this: 我的代码如下所示:
private static final String DRIVER = "com.mysql.jdbc.driver";
...
try {
try {
Class.forName(DRIVER).newInstance();
} catch (Exception e)
{
e.printStackTrace();
}
...
}
I tried to add ojdbc-14.jar to libs and reference that in gradle without success. 我试图将ojdbc-14.jar添加到库中,并在gradle中对其进行引用,但未成功。 I also use some groovy code in the build.settings but without success, I'm not sure how to work with that either. 我还在build.settings中使用了一些时髦的代码,但是没有成功,我也不知道如何使用它。
The error is in your DRIVER string. 该错误在您的DRIVER字符串中。 It should be 它应该是
DRIVER = "com.mysql.jdbc.Driver"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.