简体   繁体   中英

Cannot connect to database [default]

I have just started working on play framework. I am trying to build rest api, and is using postgresql for my db connection. It is my first time using both play and postgre. I have made a db connection inside build.sbt. But while running the app I am getting the following issue,

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
    at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94) ~[play_2.11-2.3.6.jar:2.3.6]
    at play.api.Configuration.reportError(Configuration.scala:743) ~[play_2.11-2.3.6.jar:2.3.6]
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247) ~[play-jdbc_2.11-2.3.6.jar:2.3.6]
    at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238) ~[play-jdbc_2.11-2.3.6.jar:2.3.6]
    at scala.collection.immutable.List.map(List.scala:274) ~[scala-library-2.11.1.jar:na]
Caused by: org.postgresql.util.PSQLException: FATAL: database "localhost:5432/sampledb" does not exist
    at org.postgresql.core.v3.ConnectionFactoryImpl.readStartupMessages(ConnectionFactoryImpl.java:572) ~[postgresql-9.3-1100-jdbc41.jar:na]
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:177) ~[postgresql-9.3-1100-jdbc41.jar:na]
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64) ~[postgresql-9.3-1100-jdbc41.jar:na]
    at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:136) ~[postgresql-9.3-1100-jdbc41.jar:na]
    at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29) ~[postgresql-9.3-1100-jdbc41.jar:na]

I have postgre installed in my local in port 5432, my db configuration in application.conf looks like -

 db.default.driver=org.postgresql.Driver
 db.default.url="jdbc:postgresql:localhost:5432/sampledb"
 db.default.user=postgres
 db.default.password="test"

Any help will be highly appreciated, also I will be really grateful, if link to any good tutorial on play with java can be provided. Thanks.

I changed the url string in the format and it picked it up -

db.default.url="postgres://user:password@localhost/MyDbName"

Taken from- How to set up PostgreSQL for Play 2.0?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM