JDBC

Accessing the DB using Java Database Connectivity (JDBC) is common in applications using relational DBs. Play provides a plugin to manage the JDBC connection pool. The plugin internally uses BoneCP (http://jolbox.com/), a fast Java Database Connection pool (JDBC pool) library.

Note

To use the plugin, a dependency in the build file should be added:

val appDependencies = Seq(jdbc)

The plugin supports H2, SQLite, PostgreSQL, MySQL, and SQL. Play is bundled with an H2 database driver, but to use any of the other databases we should add a dependency on its corresponding driver:

val appDependencies = Seq( jdbc,
"mysql" % "mysql-connector-java" % "5.1.18",...)

The plugin exposes the following methods:

  • getConnection: It accepts the name of the database ...

Get Mastering Play Framework for Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.