title: Why does Play action fail with "no suitable driver found" with Slick and PostgreSQL?
body: <p>I'm writing a Scala web app using <a href="https://www.playframework.com/" rel="nofollow noreferrer">Play Framework</a> 2.1.1 using a local Postgres database along with <a href="http://slick.typesafe.com/" rel="nofollow noreferrer">Slick</a> 1.0.0, and I'm running into what seems to be a contradiction here.</p>
  
  <p>This is the error I'm running into:</p>
  
  <pre><code>[SQLException: No suitable driver found for postgres://user:password@localhost:5432/postgres]
  56  
  57  def instance = Action {
  58    Database.forURL("postgres://user:password@localhost:5432/postgres", driver = "org.postgresql.Driver") withSession {
  59      val q = Retailer.map(_.name)
  60      Ok(views.html.instance(q.list, newRForm))
  61    }
  62  }
  63
  </code></pre>
  
  <p>Where <code>user</code> and <code>password</code> are respectively the <code>username</code> and <code>password</code> of the Postgres database. </p>
  
  <p>In <a href="https://stackoverflow.com/questions/5130254/java-error-no-suitable-driver-found">java error (No suitable driver found)</a> I found:</p>
  
  <ol>
  <li>You'll need to load the driver somewhere using <code>Class.forName("org.postgresql.Driver");</code></li>
  <li>You'll need the PostgreSQL driver's jar file in the classpath of your program.</li>
  </ol>
  
  <p>In <code>Application.scala</code> I have the following block of code:</p>
  
  <pre><code>{
    println(ConfigFactory.load().getString("db.default.url"))
    println(Class.forName("org.postgresql.Driver"))
  } 
  </code></pre>
  
  <p>Rerunning <code>play compile</code> results in:</p>
  
  <pre><code>(Server started, use Ctrl+D to stop and go back to the console...)
  
  [info] play - database [default] connected at jdbc:postgresql://localhost:5432/postgres
  [info] play - Application started (Dev)
  postgres://user:password@localhost:5432/postgres
  class org.postgresql.Driver
  [error] application -
  
  ! @6ei1nhkop - Internal server error, for (GET) [/instance] -&gt;
  
  play.api.Application$$anon$1: Execution exception[[SQLException: No suitable driver found for jdbc:postgresql://user:password@localhost:5432/postgres]]
          at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.1]
          at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.1]
          at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$17$$anonfun$apply$24.apply(PlayDefaultUpstreamHandler.scala:326) [play_2.10.jar:2.1.1]
          at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$17$$anonfun$apply$24.apply(PlayDefaultUpstreamHandler.scala:324) [play_2.10.jar:2.1.1]
          at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
          at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.1]
  java.sql.SQLException: No suitable driver found for jdbc:postgresql://user:password@localhost:5432/postgres
          at java.sql.DriverManager.getConnection(Unknown Source) ~[na:1.7.0_21]
          at java.sql.DriverManager.getConnection(Unknown Source) ~[na:1.7.0_21]
          at scala.slick.session.Database$$anon$2.createConnection(Database.scala:105) ~[slick_2.10-1.0.0.jar:1.0.0]
          at scala.slick.session.BaseSession.conn$lzycompute(Session.scala:207) ~[slick_2.10-1.0.0.jar:1.0.0]
          at scala.slick.session.BaseSession.conn(Session.scala:207) ~[slick_2.10-1.0.0.jar:1.0.0]
          at scala.slick.session.BaseSession.close(Session.scala:221) ~[slick_2.10-1.0.0.jar:1.0.0]
  </code></pre>
  
  <p>Then I run <code>play dependencies</code> and the postgres .jar is resolved!</p>
  
  <pre><code>Here are the resolved dependencies of your application:
  +--------------------------------------------------------+--------------------------------------------------------+-----------------------------------+
  | ←[32mpostgresql:postgresql:9.1-901-1.jdbc4←[0m         | ←[37mats:ats_2.10:1.0-SNAPSHOT←[0m                     | ←[37mAs postgresql-9.1-901-1.jdbc4.jar←[0m |
  +--------------------------------------------------------+--------------------------------------------------------+-----------------------------------+
  </code></pre>
  
  <p>Why can't a suitable driver be found?</p>
  
  <p><strong>conf/application.conf</strong></p>
  
  <pre><code># Database configuration
  db.default.driver=org.postgresql.Driver
  db.default.url="jdbc:postgres://user:password@localhost:5432/postgres"
  db.default.user=user    
  db.default.password=password
  </code></pre>
  
  <p><strong>project/Build.scala</strong></p>
  
  <pre><code>import sbt._
  import Keys._
  import play.Project._
  
  object ApplicationBuild extends Build {
  
    val appName    = "ats"
    val appVersion = "1.0-SNAPSHOT"
  
    val appDependencies = Seq(
      // Add your project dependencies here, 
      jdbc,
      "com.typesafe.slick" %% "slick"      % "1.0.0",
      "postgresql"         %  "postgresql" % "9.1-901-1.jdbc4"
    )
  
    val main = play.Project(appName, appVersion, appDependencies).settings(
      // Add your own project settings here    
    )
  </code></pre>
  
  <p>I also have <code>postgresql-9.2-1002.jdbc4.jar</code> and <code>slick_2.10-1.0.1-RC1.jar</code> in my <code>/lib</code> file, and my local Postgres version from doing a <code>SELECT version();</code> is <strong>9.2.4</strong> The postgres driver resolution seems to be resolving to the 9.1 .jar though, and when I comment out the app dependency to let <code>/lib</code> be included on its own, <code>/lib</code> doesn't seem to be on Play's CLASSPATH.</p>
  
  <p>I know that the Postgres url is correct, and I'm able to connect to my database when my application first launches. </p>