开发者

Grails can't find MySQL connector class

In order to get MySQL working with a Grails app, I copied the JAR from the apt package (using Ubuntu Server 10.10, file is "/usr/share/java/mysql-connector-java-5.1.10.jar") to the Grails application's "lib" directory.

Then in the data source settings I cha开发者_开发百科nged the database URL to url = "jdbc:mysql://127.0.0.1:3306/databasename?autoreconnect=true".

But now running the app gives me the error "ClassNotFoundException: org.mysql.jdbc.Driver". Similar problems on the mailing list didn't provide a solution to this. I've also tried to add the connector as dependency (+ Maven repos) but that didn't work either.

The JAR is obviously the correct file, so what can I do about this?


Change the driver name to:

com.mysql.jdbc.Driver


I had the same issue when I run grails (version 2.0) alone, but when I run it with SpringSTS (or another IDE) there is no problem, so, I compared the project generated by grails (alone) and generated by spring sts.

The main difference between them was the .classpath file (located in projectroot/.classpath). To solve the problem in the project generated without sts I've added the next line to .classpath file

<classpathentry kind="lib" path="lib/mysql-connector-java-5.1.18-bin.jar"/>

I hope this work for you.


In DataSource.groovy:

dataSource {
    driverClassName = "com.mysql.jdbc.Driver"
    username = "xxx"
    password = "yyy"
}

...

environments {
    development {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://127.0.0.1/databasename?useUnicode=true&characterEncoding=utf8&autoReconnect=true"
...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜