22

Has anyone gotten Grails working with Postgres? I have used this tutorial and everything seems to make sense and be correct to me. However when I 'grails run-app' I get this error

Cannot create JDBC driver of class 'org.postgresql.Driver' for connect URL 'jdbc:postgres://10.0.0.21/tribes'
java.sql.SQLException: No suitable driver

My DataSource file is

dataSource {
    pooled = true
    driverClassName = "org.postgresql.Driver"
    dialect = org.hibernate.dialect.PostgreSQLDialect
}
hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "update"
            url = "jdbc:postgres://10.0.0.21:5432/tribes"
            username = "grails"
            password = "grails"
        }   
    }   
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:postgres://10.0.0.21:5432/tribes"
            username = "grails"
            password = "grails"
        }   
    }   
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:postgres://10.0.0.21:5432/tribes"
            username = "grails"
            password = "grails"
        }   
    }   
}
1
  • yes. I have tried several versions anyway but am pretty sure I have the right one Commented Oct 6, 2009 at 20:49

2 Answers 2

23

From the FAQ: "[if] you get a runtime error that says 'No suitable driver found', it is likely that the URL passed to DriverManager.getConnection is malformed or otherwise incorrect". So what's wrong with yours? Well, the examples in the tutorial look like this:

jdbc:postgresql://localhost:5432/grails

Yours looks like this:

jdbc:postgres://10.0.0.21:5432/tribes

I'm guessing those missing two letters are causing your trouble.

Sign up to request clarification or add additional context in comments.

Comments

19

In the BuildConfig.groovy file uncomment the external maven repositories and then add this line

runtime 'postgresql:postgresql:9.0-801.jdbc4' in the dependencies section

2 Comments

This line is essential to getting Grails talking to Postgresql. But you don't need to uncomment any external Maven repos if you have already copied the Postgresql JDBC jar to your project/lib directory. Also, you need to create the database that you reference in your JDBC url before you do grails run-app.
Updating this since it's been awhile since the answer, and the version of the postgresql driver has been upgraded. The current driver (as of Jan 2014) is: runtime 'org.postgresql:postgresql:9.3-1100-jdbc4' This is for JDK 1.6. You'll need to change that last 'jdbc4' to 'jdbc3' if you're still running JDK 1.5. For more info see jdbc.postgresql.org/download.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.