Play Unable to connect to database (PostgreSQL) [default]

I get

CreationException: Unable to create injector, see the following errors: 1) Error in custom provider, Configuration error: Configuration error[Cannot connect to database [default]] [...] 2) Error in custom provider, Configuration error: Configuration error[Cannot connect to database [default]] 

The full stack trace is here: http://hastebin.com/ahacepifaf.txt

Initially, I had a MySQL database used with the Play Framework application that worked, but I wanted to change it to PostgreSQL and that problems occurred if problems occurred. I installed them both on my Ubuntu computer and changed the playback configuration to use Postgres (added "postgresql" % "postgresql" % "9.1-901-1.jdbc4", in build.sbt and changed the db.default properties for the link Postgres). Exact application.conf :

 db.default.driver="org.postgresql.Driver" db.default.url="jdbc:postgres://localhost:5432/playdb" db.default.username="luka" db.default.password="test" 

I manually created luka user using password test and playdb database. I tried with the postgres user too, but to no avail.

What bothers me more, MySQL will not work either with the same error. I created a new project only by changing the db.default parameters in conf and it fails in the same way. Commenting out application.conf makes it go away, so there is definitely a problem. I checked the PostgreSQL logs ( /var/log/postgresql/postgresql-9.4-main.log ), and only the line that seems wrong is [unknown]@[unknown] LOG: invalid length of startup packet . It appears several times, but not every time I update a project (I'm not even sure if this is related). I uninstalled mysql-server from my PC, hoping that everything would magically consolidate. This is not true.

Ideas?

I use Play 2. 4. 6 and IntelliJ IDEA 15. The project is created using Activator and imports sources into IDEA (using the SBT model).

EDIT When I add db.default.hikaricp.connectionTestQuery = "SELECT 1" to my application.conf , I get the following error: http://hastebin.com/hazoraradi.txt

+5
source share
4 answers

So the specific answer is:

Firstly, there is an error in the database URL, it should be db.default.url="jdbc:postgresql://localhost:5432/playdb" as specified by chabeee . This is the only correct format for db.default.url (therefore no jdbc:postgresql://username:pasword:localhost/dbname or similar, as I saw elsewhere).

Secondly, it is more complicated that there is an error in the driver, as Salem pointed out , and the workaround adds db.default.hikaricp.connectionTestQuery = "SELECT 1" to application.conf .
However, this bug has been fixed (well, this workaround is implemented) in versions later than 9.1-903 . The trick after version 9.1-901 postgresql has changed its groupID in repositories and now references org.postgresql . A better solution than a workaround would be to update the dependencies on "org.postgresql" % "postgresql" % "9.4-1206-jdbc4" ( current version , MVNrepository ). Add the appropriate jdbc version to the latest PostgreSQL driver ( 4 for Java 6, 41 for Java 7, 42 for Java 8).

My last application.conf :

 db.default.driver="org.postgresql.Driver" db.default.url="jdbc:postgresql://localhost/playdb" #the port is optional db.default.username="luka" db.default.password="test" 

And libraryDependencies in build.sbt :

 libraryDependencies ++= Seq( jdbc, "org.postgresql" % "postgresql" % "9.4-1206-jdbc42", cache, javaWs ) 

UPDATE 2017: I just noticed that shortly after writing this answer, they changed the version control scheme and removed the -jdbc [code] snippet, replacing it with .jre6, .jre7 or nothing, which apparently meant for the latest version of Java (I haven’t found anything supporting this statement, but it works). Back in February 2017, they again changed the version scheme and switched from the main version from 9 to 42, making the current version (as of July 17, 2017), denoted by "org.postgresql" % "postgresql" % "42.1.3" (or, respectively, "org.postgresql" % "postgresql" % "42.1.3.jre7" / "org.postgresql" % "postgresql" % "42.1.3.jre6" )

+10
source

From your stacktrace

JDBC4 Connection.isValid () method is not supported, connection testing request must be configured

This is mainly a problem with your driver (it does not support this method), but you should be able to get around it by specifying a test request in application.conf :

 play.db.default.hikaricp.connectionTestQuery = "SELECT 1" 
+1
source

Try replacing this line:

 db.default.url="jdbc:postgres://localhost:5432/playdb" 

:

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

Hope this helps.

+1
source

Are you by any chance on a Mac, and do you have a postgresql.jar file in the /Library/Java/Extensions directory?

Edit: Sorry, I'm new. I came across the message "JDBC4 Connection.isValid () is not supported" when using Hikari on my Mac, and I decided to find it and delete the JDBC3.jar file in this extensions directory. I don’t know how this happened (maybe when I installed PostgreSQL or some related tool), but I found that it will be loaded instead of any JDBC4.jar file in my class path. Perhaps something like this is happening in Ubuntu. Probably worth checking out, as other issues related to JDBC4 may occur besides "isValid ()".

0
source

Source: https://habr.com/ru/post/1238434/


All Articles