title: Play Framework with Scala, cannot connect to database JDBC Postgresql
body: <p>I'm following along with the <a href="https://www.manning.com/books/play-for-scala" rel="nofollow">"Play for Scala"</a> book. I'm currently trying to setup a connection to the PostgreSQL database I have running on my machine, however I cannot connect, I'm not sure why. A co-worker of mine has a project using Play with PostgreSQL as well, the project is cloned to the same machine with PostgreSQL running, and it works just fine. </p>
  
  <p>I am getting the following error:</p>
  
  <pre><code>[info] - application - Creating Pool for datasource 'default'
  [error] - application - 
  
  ! @6pb6jk4k6 - Internal server error, for (GET) [/products] -&gt;
  
  play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
          at play.api.Configuration$.configError(Configuration.scala:178) ~[play_2.11-2.4.6.jar:2.4.6]
          at play.api.Configuration.reportError(Configuration.scala:829) ~[play_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:48) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at scala.collection.immutable.List.foreach(List.scala:381) ~[scala-library-2.11.7.jar:na]
          at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DBApiProvider.get(DBModule.scala:62) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DBApiProvider.get(DBModule.scala:58) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81) ~[guice-4.0.jar:na]
          at com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72) ~[guice-4.0.jar:na]
          at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61) ~[guice-4.0.jar:na]
          at com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62) ~[guice-4.0.jar:na]
          at com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:54) ~[guice-4.0.jar:na]
          at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132) ~[guice-4.0.jar:na]
          at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93) ~[guice-4.0.jar:na]
          at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80) ~[guice-4.0.jar:na]
          at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103) ~[guice-4.0.jar:na]
          at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80) ~[guice-4.0.jar:na]
          at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:62) ~[guice-4.0.jar:na]
          at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:984) ~[guice-4.0.jar:na]
          at com.google.inject.util.Providers$GuicifiedProviderWithDependencies.initialize(Providers.java:149) ~[guice-4.0.jar:na]
          at com.google.inject.util.Providers$GuicifiedProviderWithDependencies$$FastClassByGuice$$2a7177aa.invoke(&lt;generated&gt;) ~[guice-4.0.jar:na]
          at com.google.inject.internal.cglib.reflect.$FastMethod.invoke(FastMethod.java:53) ~[guice-4.0.jar:na]
          at com.google.inject.internal.SingleMethodInjector$1.invoke(SingleMethodInjector.java:57) ~[guice-4.0.jar:na]
          at com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector.java:91) ~[guice-4.0.jar:na]
          at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132) ~[guice-4.0.jar:na]
          at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93) ~[guice-4.0.jar:na]
          at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80) ~[guice-4.0.jar:na]
          at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092) ~[guice-4.0.jar:na]
          at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80) ~[guice-4.0.jar:na]
          at com.google.inject.internal.Initializer$InjectableReference.get(Initializer.java:174) ~[guice-4.0.jar:na]
          at com.google.inject.internal.Initializer.injectAll(Initializer.java:108) ~[guice-4.0.jar:na]
          at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:174) ~[guice-4.0.jar:na]
          at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110) ~[guice-4.0.jar:na]
          at com.google.inject.Guice.createInjector(Guice.java:96) ~[guice-4.0.jar:na]
          at com.google.inject.Guice.createInjector(Guice.java:73) ~[guice-4.0.jar:na]
          at com.google.inject.Guice.createInjector(Guice.java:62) ~[guice-4.0.jar:na]
          at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:126) ~[play_2.11-2.4.6.jar:2.4.6]
          at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:93) ~[play_2.11-2.4.6.jar:2.4.6]
          at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21) ~[play_2.11-2.4.6.jar:2.4.6]
          at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:153) ~[play-server_2.11-2.4.6.jar:2.4.6]
          at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1$$anonfun$2.apply(DevServerStart.scala:150) ~[play-server_2.11-2.4.6.jar:2.4.6]
          at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.11-2.4.6.jar:2.4.6]
          at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:150) ~[play-server_2.11-2.4.6.jar:2.4.6]
          at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
          at scala.Option.map(Option.scala:146) ~[scala-library-2.11.7.jar:na]
          at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
          at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
          at scala.util.Success.flatMap(Try.scala:231) ~[scala-library-2.11.7.jar:na]
          at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
          at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:111) ~[play-server_2.11-2.4.6.jar:2.4.6]
          at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library-2.11.7.jar:na]
          at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.11.7.jar:na]
          at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) ~[na:1.8.0_66]
          at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[na:1.8.0_66]
          at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[na:1.8.0_66]
          at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[na:1.8.0_66]
          at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) ~[na:1.8.0_66]
  Caused by: play.api.Configuration$$anon$1: Configuration error[Exception during pool initialization]
          at play.api.Configuration$.configError(Configuration.scala:178) ~[play_2.11-2.4.6.jar:2.4.6]
          at play.api.PlayConfig.reportError(Configuration.scala:1048) ~[play_2.11-2.4.6.jar:2.4.6]
          at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:69) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.PooledDatabase.createDataSource(Databases.scala:199) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DefaultDatabase.dataSource$lzycompute(Databases.scala:124) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DefaultDatabase.dataSource(Databases.scala:122) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DefaultDatabase.getConnection(Databases.scala:143) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DefaultDatabase.getConnection(Databases.scala:139) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:44) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          ... 56 common frames omitted
  Caused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
          at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:542) ~[HikariCP-2.3.7.jar:na]
          at com.zaxxer.hikari.pool.BaseHikariPool.&lt;init&gt;(BaseHikariPool.java:171) ~[HikariCP-2.3.7.jar:na]
          at com.zaxxer.hikari.pool.HikariPool.&lt;init&gt;(HikariPool.java:60) ~[HikariCP-2.3.7.jar:na]
          at com.zaxxer.hikari.pool.HikariPool.&lt;init&gt;(HikariPool.java:48) ~[HikariCP-2.3.7.jar:na]
          at com.zaxxer.hikari.HikariDataSource.&lt;init&gt;(HikariDataSource.java:80) ~[HikariCP-2.3.7.jar:na]
          at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:58) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at play.api.db.HikariCPConnectionPool$$anonfun$1.apply(HikariCPModule.scala:54) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          at scala.util.Try$.apply(Try.scala:192) ~[scala-library-2.11.7.jar:na]
          at play.api.db.HikariCPConnectionPool.create(HikariCPModule.scala:54) ~[play-jdbc_2.11-2.4.6.jar:2.4.6]
          ... 62 common frames omitted
  Caused by: java.sql.SQLException: JDBC4 Connection.isValid() method not supported, connection test query must be configured
          at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:441) ~[HikariCP-2.3.7.jar:na]
          at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:540) ~[HikariCP-2.3.7.jar:na]
          ... 70 common frames omitted
  </code></pre>
  
  <p>Here is the relevant code in <code>application.conf</code>:</p>
  
  <pre><code>db.default.driver=org.postgresql.Driver
  db.default.url="jdbc:postgresql://localhost:5432/paperclips"
  db.default.username="postgres"
  db.default.password="postgres"
  </code></pre>
  
  <p>And in the build file:</p>
  
  <pre><code>libraryDependencies ++= Seq(
    "com.typesafe.play" %% "anorm" % "2.4.0",
    "com.adrianhurt" %% "play-bootstrap3" % "0.4.5-P24",
    "net.sf.barcode4j" % "barcode4j" % "2.0",
    "postgresql" % "postgresql" % "9.1-901.jdbc4"
  )
  </code></pre>