Accessing the default JDBC database in Play for Scala
<p><a href="https://www.playframework.com/documentation/2.5.x/ScalaDatabase" rel="nofollow">In this Play tutorial</a> it is explained how to use a JDBC connection pool, including an example to access the database. Problem is that it is not clear how to assign the default database to the <code>db</code> field.</p>

<p>For example:</p>

<pre><code>class ScalaControllerInject @Inject() extends Controller {

  def index = Action {
    var outString = "Number is "

    val db: Database = ??? // How to assign the default database to db?

    val conn = db.getConnection()

    try {
      val stmt = conn.createStatement
      val rs = stmt.executeQuery("SELECT 9 as testkey ")

      while (rs.next()) {
        outString += rs.getString("testkey")
      }
    } finally {
      conn.close()
    }
    Ok(outString)
  }

}
</code></pre>

<p>I put the db declaration in the method instead of the class parameter, but the intent is the same.</p>

<p>Note: I'm using Play 2.5.2</p>