Postgresql with Play Framework
Asked Answered
T

5

9

Im trying to use Postgresql with Play for their Yabe tutorial and get this error:

Cannot connected to the database, Driver not found (org.postgresql.Driver)

Here is my connection string:

# If you need a full JDBC configuration use the following :
 db.url=jdbc:postgresql:yabe
 db.driver=org.postgresql.Driver  
 db.user=yabe
 db.pass=yabe
#
# Connections pool configuration :
 db.pool.timeout=1000
 db.pool.maxSize=30
 db.pool.minSize=1

In my lib folder I have this: postgresql-9.1-901.jdbc3.jar

I tried changing the driver name to the same name is tha jar but still get the same error. Any ideas?

Tijuana answered 11/10, 2011 at 20:13 Comment(5)
Have you checked that the org.postgresql.Driver is in the Jar?Leftwich
Hi Niels. I didn't. I downloaded the driver from Postgresql. Ill check what you suggested.Tijuana
I added a dependency for this in the .yml file and it successfully downloads the .jar file. I still get this error though. A database error occured : Cannot connected to the database, Driver not found (postgresql-9.0-801.jdbc4.jar)Tijuana
Please check it directly by looking into the jar.Leftwich
heres whats in the jar. repo1.maven.org/maven2/postgresql/postgresql/9.0-801.jdbc4Tijuana
B
10

The Play framework already includes the driver for Postgres. do the following:

  • Remove any reference to postgreSQL drivers from your dependencies.yml files
  • Do a "play deps --sync"
  • Remove any jar in your lib/ folder related to postgreSQL drivers
  • Change your connection string to:

    db=postgres://user:pwd@localhost:5432/yabe

This should solve the conflict you have.

Boar answered 13/10, 2011 at 11:5 Comment(2)
None of this is true for Play 2Protozoal
@MikeSlinn yes, well, this was a Play 1 question :)Boar
E
40

If you are using Play 2.0 this works slightly differently. The url actually looks like this:

db.default.driver=org.postgresql.Driver
db.default.url="postgres://user:password@servername/dataBaseName"

But this will also error out unless you add the following lines to you dependencies section in build.scala or build.java:

"postgresql" % "postgresql" % "9.1-901.jdbc4"
Echt answered 28/5, 2012 at 15:12 Comment(0)
D
13

If you need SSL support:

db=postgres://user:[email protected]:5432/dbname?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory
Derwon answered 8/12, 2011 at 14:45 Comment(0)
B
10

The Play framework already includes the driver for Postgres. do the following:

  • Remove any reference to postgreSQL drivers from your dependencies.yml files
  • Do a "play deps --sync"
  • Remove any jar in your lib/ folder related to postgreSQL drivers
  • Change your connection string to:

    db=postgres://user:pwd@localhost:5432/yabe

This should solve the conflict you have.

Boar answered 13/10, 2011 at 11:5 Comment(2)
None of this is true for Play 2Protozoal
@MikeSlinn yes, well, this was a Play 1 question :)Boar
K
6

You don't need to edit a full JDBC configuration. I use postgesql in local and I just add this line in application.conf file in conf folder :

# To connect to a local PostgreSQL9 database, use:
db=postgres://userName:yourPassword@localhost:5432/nameOfYourDB

If you are in local, userName is often postgres unless you changed it.

Kalamazoo answered 11/10, 2011 at 21:15 Comment(1)
I tried what you suggested and this is the error i receive: A JPA error occurred (Cannot start a JPA manager without a properly configured database): No datasource configuredTijuana
U
3

You should copy PostgresSql driver version "JDBC 4" [What you have is JDBC 3]. Get it from here

Alternatively you may use - postgresql 9.1-901.jdbc4 in your dependencies. But I think Maven doesn't have this latest version yet.

Unclasp answered 12/10, 2011 at 23:58 Comment(4)
Copy? Doesn't the dependency pull it down?Tijuana
Dependency will pull it down if the jar is available in Maven central. But as I said, this latest version is not available yet. mvnrepository.com/artifact/postgresql/postgresqlUnclasp
It doesnt matter what version i pull down. I get an error. Here is what i have setup: application.conf db.url=jdbc:postgresql:yabe db.driver=postgresql-9.0-801.jdbc4.jar db.user=yabe db.pass=password dependancies.yml require: - play - postgresql -> postgresql 9.0-801.jdbc4 The error: A database error occured : Cannot connected to the database, Driver not found (postgresql-9.0-801.jdbc4.jar) What am I doing wrong?Tijuana
libraryDependencies += "postgresql" % "postgresql" % "9.1-901.jdbc4"Nudd

© 2022 - 2024 — McMap. All rights reserved.