score:17

Accepted answer

You are mixing things up.

So then I looked at this question which says...

  1. You'll need to load the driver somewhere. Class.forName("org.postgresql.Driver");
  2. You'll need the postgresql driver .jar file in the classpath of your program.

This is not applicable in this case. You have a framework that takes care of these things for you. That question you refer to is describing how to access a database with "raw" jdbc.


Here's how you should do it.

First of all you can simplify the configuration part. 5432 is the default port for postresql and localhost is also the default host. Username and password should be placed outside of the url.

# Database configuration
db.default.driver=org.postgresql.Driver
db.default.url=jdbc:postgres:postgres
db.default.user=user    
db.default.password=password

Now define proper sbt dependencies. Just remove the jar files from the /lib folder and update your dependencies to get the latest PostgreSQL driver (9.2) by changing your Build.scala appDependencies. Be aware that the groupId has changed from postgresql to org.postgresql.

val appDependencies = Seq(
  // Add your project dependencies here, 
  jdbc,
  "com.typesafe.slick" %% "slick" % "1.0.0",
  "org.postgresql" % "postgresql" % "9.3-1102-jdbc41"
)

And finally you should change your controller to resolve the datasource from configuration:

def instance = Action {
  Database.forDataSource(DB.getDataSource()) withSession {
    val q = Retailer.map(_.name)
    Ok(views.html.instance(q.list, newRForm))
  }
}

Related Query

More Query from same tag