Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Steps needed to use MySQL database with Play framework 2.0

I'm new to Play framework. I'm trying to configure MySQL database as a datasource to be used with Play Ebeans.

Could you some one please explain the steps that are needed to configure MySQL with Play 2.0 framework (like, downloading drivers, adding dependency etc).

like image 925
Veera Avatar asked Apr 04 '12 07:04

Veera


People also ask

How do you use Ebean in play framework?

To customise the underlying Ebean Server configuration, you can either add a conf/ebean. properties file, or create an instance of the ServerConfigStartup interface to programmatically manipulate the Ebean ServerConfig before the server is initialised. Note that Ebean will also make use of a conf/orm.

What JDBC driver used to connect to MySQL?

The MySQL JDBC driver is called MySQL Connector/J.


1 Answers

Look at this page from Play's documentation. It says:

Other than for the h2 in-memory database, useful mostly in development mode, Play 2.0 does not provide any database drivers. Consequently, to deploy in production you will have to add your database driver as an application dependency.

For example, if you use MySQL5, you need to add a dependency for the connector:

val appDependencies = Seq(     // Add your project dependencies here,     ...     "mysql" % "mysql-connector-java" % "5.1.18"     ... ) 

SBT will download the driver for you. You should also check out the section on managing dependencies.

To connect to MySQL, you will also need to change some settings in your application.conf:

db.default.driver=com.mysql.jdbc.Driver db.default.url="mysql://root:secret@localhost/myDatabase" 
like image 76
Carsten Avatar answered Oct 14 '22 08:10

Carsten