Play framework2 Development (6)

Source: Internet
Author: User
Tags custom name

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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.