我尝试使用播放框架工作连接到Postgresql。我尝试了一切,但我仍然无法解决这个问题
db.default.user=user
db.default.password=qwerty
db.default.url="jdbc:postgresql://localhost:5432/paperclips"
db.default.driver=org.postgresql.Driver
但是我收到以下错误:无法连接到数据库[默认]
[error] c.j.b.h.AbstractConnectionHook - Failed to obtain initial connection Sleeping for 0ms and trying again. Attempts left: 0. Exception: java.net.ConnectException: Connection refused.Message:Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
[error] application -
! @6hmjgfh72 - Internal server error, for (GET) [/] ->
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:92) ~[play_2.10.jar:2.2.2]
at play.api.Configuration.reportError(Configuration.scala:570) ~[play_2.10.jar:2.2.2]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:252) ~[play-jdbc_2.10.jar:2.2.2]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:243) ~[play-jdbc_2.10.jar:2.2.2]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library.jar:na]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library.jar:na]
Caused by: org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:22) ~[postgresql-9.1-901.jdbc4.jar:na]
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:30) ~[postgresql-9.1-901.jdbc4.jar:na]
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.6.0_65]
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:382) ~[na:1.6.0_65]
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:241) ~[na:1.6.0_65]
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:228) ~[na:1.6.0_65]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:431) ~[na:1.6.0_65]
at java.net.Socket.connect(Socket.java:527) ~[na:1.6.0_65]
答案 0 :(得分:0)
在档案 application.conf :
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/dataBaseName"
db.default.user=user
db.default.password="password"
在主项目(/)中创建路径 / lib ,并添加 .jar do postgresql。
下载here,然后重新加载项目。
或者在 build.sbt :
中添加此代码libraryDependencies ++= Seq(
"org.postgresql" % "postgresql" % "9.2-1003-jdbc4",
javaJdbc,
javaEbean,
cache,
javaWs
)