Setting-up DB

Setting-up DB

  1. [app]/lib/
    1. JDBC Driver
  2. conf/application.conf
    1. db.*=*
    2. In the JPA Configuration Section you have to choose the JPA (Hibernate) dialect.
  3. Now you just need to restart the server.

PostgreSQL

 db.url=jdbc:postgresql:playdb
 db.driver=org.postgresql.Driver

01:16:43,292 INFO  ~ Connected to jdbc:postgresql:playdb
01:16:43,294 INFO  ~ Application 'HelloWorld' is now started !

Oralce

db.url=jdbc:oracle:thin:@yourdatabaseserver:1521:dbname 
db.driver=oracle.jdbc.driver.OracleDriver



db.user=yourusername
db.pass=yourpassword




One more thing before starting to code. For the blog engine, we will need a database. For development purposes, Play comes with a stand alone SQL database management system called HSQLDB. This is the best way to start a project before switching to a more robust database if needed. You can choose to have either an in-memory database or a filesystem database that will keep your data between application restarts.

At the beginning, we will do a lot of testing and changes in the application model. For that reason, it’s better to use an in-memory database so we always start with a fresh data set.

To set-up the database, open the yabe/conf/application.conf file and uncomment this line:

db=mem

As you can see in the comments, you can easily set-up any JDBC compliant database and even configure the connection pool.

Now, go back to your browser and refresh the welcome page. Play will automatically start the database. Check for this line in the application logs:

INFO  ~ Connected to jdbc:hsqldb:mem:playembed

Application.conf

# Database configuration
# ~~~~~ 
# Enable a database engine if needed.
#
# To quickly set up a development database, use either:
#   - mem : for a transient in memory database (HSQL in memory)
#   - fs  : for a simple file written database (HSQL file stored)
# db=mem
#
# To connect to a local MySQL5 database, use:
# db=mysql:user:pwd@database_name
#
# If you need a full JDBC configuration use the following :
# db.url=jdbc:postgresql:database_name
# db.driver=org.postgresql.Driver
# db.user=root
# db.pass=secret
#
# Connections pool configuration :
# db.pool.timeout=1000
# db.pool.maxSize=30
# db.pool.minSize=10
#
# If you want to reuse an existing Datasource from your application server, use:
# db=java:/comp/env/jdbc/myDatasource

# JPA Configuration (Hibernate)
# ~~~~~
#
# Specify the custom JPA dialect to use here (default to guess):
# jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
#
# Specify the ddl generation pattern to use. Set to none to disable it 
# (default to update in DEV mode, and none in PROD mode):
# jpa.ddl=update
#
# Debug SQL statements (logged using DEBUG level):
# jpa.debugSQL=true
#
# You can even specify additional hibernate properties here:
# hibernate.use_sql_comments=true
# ...

# Memcached configuration
# ~~~~~ 
# Enable memcached if needed. Otherwise a local cache is used.
# memcached=enabled
#
...



Subpages (2): JPA scaffold [scaffold]
Comments