0

I cannot configure my Play framework PostgreSQL connection with regular string like below:

db.default.driver=org.postgresql.Driver
db.default.url="postgres://localhost:5432/mydb"

I get the error "Cannot connect to database [default]".

It works if I change the URL to:

db.default.url="jdbc:postgresql://localhost:5432/mydb"

But I would like to stick with the former version as the environment is already configured with such variable.

I'm using the latest Play (2.3.8) with Java 1.8 and the following JDBC driver:

libraryDependencies += "org.postgresql" % "postgresql" % "9.4-1201-jdbc4"

It looks like working if the connection string contains the username / password information:

db.default.url="postgres://postgres:postgres@localhost:5432/mydb"

Is it a limitation or am I missing something?

2 Answers 2

1

What you have put here:

db.default.url="postgres://localhost:5432/mydb"

is not a 'regular string', but an incorrect value.

Even if you manage to find a way to stick with it (Play is open sourced, so nobody can stop you), it is going to confuse every developer looking at this setting, and this includes future you.

Using configuration keys out of their original context is a risky practice that brought you here, so you should fight that rather than the framework. If you want to avoid repeating your configuration string then what you should do is something like this:

my.db.address="localhost:5432/mydb"
db.default.url="jdbc:postgresql://"${my.db.address}
my.reusable.key="postgres://"${my.db.address}

And use my.reusable.key where needed, while letting db.default.url serve it's purpose.

Answering your doubt about possible limitations, I think you might have missed this piece of documentation that explicitly numbers out correct configuration strings: https://www.playframework.com/documentation/2.3.8/SettingsJDBC

Sign up to request clarification or add additional context in comments.

2 Comments

Actually jdbc:postgres:// doesn't work. It should be jdbc:postgresql://. Anyway thanks.
Right :) Edited my answer.
0

you need to specify jdbc in the front of the url to know which driver to be loaded which handles database connectivity

1 Comment

But this is exactly what I would like to avoid :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.