【问题标题】:How to configure Play an JDBC with Postgresql?如何使用 Postgresql 配置 Play JDBC?
【发布时间】:2016-02-11 06:08:19
【问题描述】:

这是我的 postgres 版本postgresql/9.4.1

这是我的播放版本addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6")

这是我的libraryDependencies

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,
  specs2 % Test,
  "postgresql" % "postgresql" % "9.1-901-1.jdbc4"

)

将版本更改为9.4-1201-jdbc41 会得到sbt.ResolveException: unresolved dependency: postgresql#postgresql;9.4-1201-jdbc41: not found

这是我的 application.conf

db.default.driver=org.postgresql.Driver
# I tried the following combination
#db.default.url="postgres://user:pass@localhost/20160210_scala_play"

# And

db.default.url="jdbc:postgresql://localhost/20160210_scala_play"
db.default.user="user"
db.default.password="pass"

所有结果

`Cannot connect to database`

我验证了

psql \list

确实包含

20160210_scala_play

user=user password=password

谁能给我指个方向?

【问题讨论】:

标签: postgresql scala jdbc playframework


【解决方案1】:

默认情况下,postgresql 会监听端口5432。因此,除非您确定您的 postgre 实例在端口 80 上运行,否则将您的 JDBC url 更改为:

jdbc:postgresql://localhost:5432/20160210_scala_play

而且,这种依赖关系也为我解决了:

"org.postgresql" % "postgresql" % "9.4-1206-jdbc42"

【讨论】:

  • 我用"9.4-1206-jdbc42"得到了这个(*:update) sbt.ResolveException: unresolved dependency: postgresql#postgresql;9.4-1206-jdbc42: not found
  • 保留旧驱动并尝试连接端口5432
  • 看起来您在依赖项的 groupId 中错过了一个“org”。在此处查看有关此版本驱动程序的更多信息:mvnrepository.com/artifact/org.postgresql/postgresql/…
【解决方案2】:

试试

db.default.hikaricp.dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
db.default.hikaricp.dataSource.user=user
db.default.hikaricp.dataSource.password=pass
db.default.hikaricp.dataSource.databaseName=20160210_scala_play
db.default.hikaricp.dataSource.serverName=localhost

并使用此驱动程序:

"org.postgresql" % "postgresql" % "9.4-1206-jdbc41"

【讨论】:

    猜你喜欢
    • 2015-08-25
    • 2014-06-23
    • 1970-01-01
    • 1970-01-01
    • 2018-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多