播放无法连接到(PostgreSQL)数据库[​​默认]

前端之家收集整理的这篇文章主要介绍了播放无法连接到(PostgreSQL)数据库[​​默认]前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我越来越
CreationException: Unable to create injector,see the following errors: 
1) Error in custom provider,Configuration error: Configuration error[Cannot connect to database [default]]
[...]
2) Error in custom provider,Configuration error: Configuration error[Cannot connect to database [default]]

最初我使用了与Play Framework应用程序一起工作的MysqL数据库,但是我想把它改成Postgresql,那就是问题开始出现的时候.我已经在我的Ubuntu计算机上安装了它们并更改了播放配置以使用Postgres(添加了“postgresql”%“postgresql”%“9.1-901-1.jdbc4”,以构建.sb并更改了db.default属性以引用Postgres ).确切的application.conf是:

db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgres://localhost:5432/playdb"
db.default.username="luka"
db.default.password="test"

我已手动创建用户luka与密码测试和数据库playdb.我已经尝试过postgres用户也无济于事.

更让我感到困扰的是,MysqL现在无法使用相同的错误.我创建了一个新项目,只修改了conf中的db.default参数,它以同样的方式失败.注释掉application.conf会让它消失,所以这肯定是问题所在.我检查了Postgresql日志(/var/log/postgresql/postgresql-9.4-main.log),只有看起来不正确的行是[未知] @ [未知] LOG:启动数据包的长度无效.它出现多次,但不是每次我刷新项目(我甚至不确定它是否相关).我已经从我的电脑中删除MysqL-server,希望一切都能神奇地修复自己.它没有.

想法?

我正在使用Play 2. 4. 6和IntelliJ IDEA 15.使用Activator创建项目并将源导入IDEA(使用SBT模型).

编辑我将db.default.hikaricp.connectionTestQuery =“SELECT 1”添加到我的application.conf时也遇到错误.

所以,明确的答案是:

首先,数据库url中有一个错误,它应该是db.default.url =“jdbc:postgresql:// localhost:5432 / playdb”为chabeee pointed out.这是db.default.url唯一正确的格式(所以没有jdbc :postgresql://用户名:pasword:localhost / dbname或类似的,正如我在其他地方看到的那样建议).

第二,更棘手的是,驱动程序中有一个错误,因为Salem pointed out解决方法是将db.default.hikaricp.connectionTestQuery =“SELECT 1”添加到application.conf.
但是,在比9.1-903更新的版本中修复了这个错误(好了,解决方法已经实现).问题是,在版本9.1-901之后,postgresql在repos中更改了它的groupID,现在它被org.postgresql引用.比解决方法更好的解决方案是将依赖关系更新为“org.postgresql”%“postgresql”%“9.4-1206-jdbc4”(current version,MVNrepository).将适当的jdbc版本附加到最新的Postgresql驱动程序(4个用于Java 6,41个用于Java 7,42个用于Java 8).

我最后的application.conf:

db.default.driver="org.postgresql.Driver"
db.default.url="jdbc:postgresql://localhost/playdb" #the port is optional
db.default.username="luka"
db.default.password="test"

和build.sbt中的libraryDependencies:

libraryDependencies ++= Seq(
  jdbc,"org.postgresql" % "postgresql" % "9.4-1206-jdbc42",cache,javaWs
)

2017年更新:
我现在才注意到,在写完这个答案后不久,他们改变了版本控制方案并删除了-jdbc [code]片段,将其替换为.jre6,.jre7或者什么也没有,显然意味着它适用于最新的Java版本(我没有发现支持这种说法的任何东西,但它确实有效).然而在2017年2月它们又是changed the version scheme again并从主要版本9跳到42,使当前版本(截至2017年7月17日)表示为“org.postgresql”%“postgresql”%“42.1.3”(或相应地,“ org.postgresql“%”postgresql“%”42.1.3.jre7“/”org.postgresql“%”postgresql“%”42.1.3.jre6“)

原文链接:https://www.f2er.com/postgresql/191826.html

猜你在找的Postgre SQL相关文章