postgresql 在 Grails 中使用 Postgres

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1527673/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 22:21:32  来源:igfitidea点击:

Using Postgres with Grails

postgresqlgrails

提问by Joe Cannatti

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

有没有人让 Grails 与 Postgres 一起工作?我已经使用了本教程,一切似乎都有意义并且对我来说是正确的。但是,当我“grails run-app”时出现此错误

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"
        }   
    }   
}

回答by Greg Smith

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:

来自常见问题解答:“[如果] 您收到一个运行时错误,提示'找不到合适的驱动程序',很可能是传递给 DriverManager.getConnection 的 URL 格式错误或不正确”。那么你的有什么问题吗?好吧,教程中的示例如下所示:

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.

我猜那些丢失的两个字母会给你带来麻烦。

回答by Ganesh Krishnan

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

在 BuildConfig.groovy 文件中取消注释外部 maven存储库,然后添加这一行

runtime 'postgresql:postgresql:9.0-801.jdbc4'in the dependenciessection

依赖项部分中的运行时“postgresql:postgresql:9.0-801.jdbc4”