dosaki
dosaki

Reputation: 113

Getting 'java.sql.SQLException: com.mysql.jdbc.Driver' with grails run-app (when BuildConfig.groovy doesn't need to be recompiled)

I've upgraded my grails application from 1.3.9 to 2.2.3 and then to 2.3.3. I read the release and upgrade notes for 1.3.9->2.2.3 and then from 2.2.3->2.3.3

I am using OpenJDK 6, Jetty 6 and the plugin jetty 1.1, MySQL 5.5 and I have the connector library under lib

Now my issue is if I run grails clean and then grails run-app the application runs without any problems but if I stop it and run grails run-app again I get a gigantic error (see here: http://pastebin.com/36MpXhir)

I also found that changing something like adding a space somewhere in BuildConfig.groovy (anything that makes it be recompiled) makes the application run normally.

Looking at the stacktrace the first thing that puzzles me is

    [02.12.13 16:13:59.919] [main] pool.ConnectionPool Unable to create initial connections of pool.
    java.sql.SQLException: com.mysql.jdbc.Driver
        at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:254)
        at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:182)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:701)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:635)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:486)
        at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:144)
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:116)
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:103)
        at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:127)
        at org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy.afterPropertiesSet(LazyConnectionDataSourceProxy.java:162)

There are references to org.apache.tomcat even though I'm using jetty (and removed tomcat from BuildConfig.groovy).

Did anyone else encounter such a problem?

Upvotes: 1

Views: 6762

Answers (2)

R.V.RaguPrashanth
R.V.RaguPrashanth

Reputation: 65

For me same error has occurred while running the Grails Application.Then I debug and view the code history of my code which was committed recently.
From that I found the issue that was:
 Inside the controller file I send the instance with-out properly
 Eg:
    **def list=[personInstance.]---> error occurred.**
    **render list as JSON**
 Then I correct my mistake-->clean the app --> run the app
 Now its working fine.

Upvotes: -1

Burt Beckwith
Burt Beckwith

Reputation: 75671

Don't put jar files in the lib directory if they're available in a public Maven repo. It's far better to download jars once and keep them in a local cache, and reuse them as needed.

The MySQL driver is used as the commented-out example in the generated BuildConfig.groovy - just un-comment it :) You might want to bump up the version to the latest, e.g.

dependencies {
   runtime 'mysql:mysql-connector-java:5.1.27'
}

This is a good site for finding Maven artifacts: http://mvnrepository.com/artifact/mysql/mysql-connector-java

If you do have a jar that's not in a Maven repo (e.g. one with shared code at your company) then you can put it in the lib directory, but it's not auto-discovered. Run grails compile --refresh-dependencies to get it added to the classpath.

Upvotes: 9

Related Questions