Obtain a SQL database
Configure the JDBC connection pool
Play2.0 provides a component to manage the connection pool. You can configure any number of required databases.
To make the database component work, configure the following in CONF/application. conf: (for convenience, the default JDBC data source must be named default)
For example:
db.epay.driver=com.mysql.jdbc.Driverdb.epay.url="jdbc:mysql://localhost:3306/epayDB"db.epay.user=rootdb.epay.password="1234"
Obtain the JDBC Data Source
DataSource ds = DB.getDataSource("epay");
Epay is the custom name in application. conf.
Obtain the data source through JNDI
Some Packages may need to obtain the data source from JNDI, which is added in the configuration.
db.epay.jndiName=epayDS
Introduce data source driver
Except for the H2 memory database driver used in the development mode, play2.0 does not provide any other drivers. So in production deployment, you need to add
Your Database driver depends on your application. For example, if you use mysql5, you need to add a dependency for database connection.
The play framework integrates Maven, so you only need
val appDependencies = Seq( // Add your project dependencies here, javaCore, javaJdbc, javaEbean, "mysql" % "mysql-connector-java" % "5.1.18" )
Start again, and play will download the mysql-connector-Java driver package from Maven.