forked from playframework/playframework
-
Notifications
You must be signed in to change notification settings - Fork 0
JavaDatabase
Guillaume Bort edited this page Feb 6, 2012
·
5 revisions
Play 2.0 provides a plugin for managing JDBC connection pools. You can configure as many databases you need.
To enable the database plugin, configure a connection pool in the conf/application.conf file. By convention the default JDBC data source must be called default:
# Default database configuration
db.default.driver=org.h2.Driver
db.default.url=jdbc:h2:mem:playTo configure several data sources:
# Orders database
db.orders.driver=org.h2.Driver
db.orders.url=jdbc:h2:mem:orders
# Customers database
db.customers.driver=org.h2.Driver
db.customers.url=jdbc:h2:mem:customersIf something isn’t properly configured you will be notified directly in your browser:

The play.db package provides access to the configured data sources:
import play.db.*;
DataSource ds = DB.getDatasource();The same way you can retrieve a JDBC connection:
Connection connection = DB.getConnection();
Some libraries expect to retrieve the Datasource reference from JNDI. You can expose any Play managed datasource via JDNI by adding this configuration in conf/application.conf:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.jndiName=DefaultDS
- HTTP programming
- Asynchronous HTTP programming
- The template engine
- HTTP form submission and validation
- Working with JSON
- Working with XML
- Handling file upload
- Accessing an SQL database
- Using the Cache
- Calling WebServices
- Integrating with Akka
- Internationalization
- The application Global object
- Testing your application