如何配置使用Postgresql播放JDBC?

Kev*_*vin 3 postgresql scala jdbc playframework

这是我的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"

)
Run Code Online (Sandbox Code Playgroud)

更改版本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"
Run Code Online (Sandbox Code Playgroud)

所有结果都是

`Cannot connect to database`
Run Code Online (Sandbox Code Playgroud)

我证实了这一点

psql \list
Run Code Online (Sandbox Code Playgroud)

确实包含

20160210_scala_play
Run Code Online (Sandbox Code Playgroud)

user=user password=password

有人可以指点我的方向吗?

Ali*_*ani 7

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

jdbc:postgresql://localhost:5432/20160210_scala_play
Run Code Online (Sandbox Code Playgroud)

而且,这种依赖性已经解决了我:

"org.postgresql" % "postgresql" % "9.4-1206-jdbc42"
Run Code Online (Sandbox Code Playgroud)

  • 看起来你错过了依赖关系的groupId的"组织".在此处查看有关此版本驱动程序的更多信息:http://mvnrepository.com/artifact/org.postgresql/postgresql/9.4-1206-jdbc42 (2认同)