Play framework2 development (6)

Obtain a SQL database

Configure JDBC connection pool

Play2.0 provides a component to manage the connection pool. You can configure as many databases as you need.

In order to make the database component work, configure the following in conf/application.conf: (For convenience, the default JDBC data source must be named default)

E.g:

db.epay.driver=com.mysql.jdbc.Driver
db.epay.url="jdbc:mysql://localhost:3306/epayDB"
db.epay.user=root
db.epay.password="1234"

Obtain JDBC data source

 DataSource ds = DB.getDataSource("epay");
epay is the name I customized in application.conf

Get data source through JNDI

Some packages may need to obtain data sources from JNDI, add in the configuration

db.epay.jndiName=epayDS


引入数据源驱动

除了在开发模式中有用到的h2内存数据库驱动,play2.0不提供任何其他驱动。所以在生产部署中,你得增加

你的数据库驱动作为应用程序依赖。例如,如果你使用MySQL5,你需要增加一条依赖项用于数据库连接。

play框架集成maven,所以只需要在project/Build.scala中


val appDependencies = Seq(
    // Add your project dependencies here,
    javaCore,
    javaJdbc,
    javaEbean,
     "mysql" % "mysql-connector-java" % "5.1.18"
  )
Again start , play will maven from the download-conn MySQL Ector the Java-driver package


Guess you like

Origin blog.csdn.net/penkee/article/details/8751589