Book Image

Mastering play framework for scala

By : Shiti Saxena
Book Image

Mastering play framework for scala

By: Shiti Saxena

Overview of this book

Table of Contents (21 chapters)
Mastering Play Framework for Scala
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with Play
Index

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 it should get the connection for and whether any statement executed using this connection should commit automatically or not. If a name is not provided, it fetches the connection for database with the default name.

  • withConnection: It accepts a block...