Configuring the database access

In order to be able to access to your relational database, JOnAS will create and use a DataSource object that must be configured according to the database you intend to use. These DataSource objects are configured via properties files and are reference in jonas.properties (see the section called JOnAS configuration files in the chapter called Getting started with JOnAS).

Defining a datasource

This example expects a datasource named jdbc_1 to be available in the EJB server. This is the default name used in the database properties files provided in $JONAS_ROOT/config. If there is no suitable properties file for you database, here is a quick example on how to setup one for use with MySQL and the MM-MySQL JDBC driver:

#####
#  MySQL DataSource configuration example
#
datasource.name         jdbc_1
datasource.url          jdbc:mysql://localhost/account
datasource.classname    org.gjt.mm.mysql.Driver
datasource.username     anonymous
datasource.password     
jdbc.connchecklevel	1
jdbc.connmaxage		30
jdbc.connteststmt	select 1

If you call this file mysql.properties, you must define the following line in in your jonas.properties file:

jonas.service.dbm.datasources    mysql

Creating the database

JOnAS does not automatically create the database, so you have to create it prior running the example. The Account.sql file can be used with most SQL-92 compatible databases. There is also an Account.idb file to be used with InstantDB. Here are some examples:

Check your database manual for more information. You will also have to grant the access to the database to the user defined in your database properties file. In our previous example for MySQL, we have to grant the access to the sampleaccount database to the user anonymous without password from the local host. You can find how to grant or revoke accesses to databases in your database administration manual.

Additional information about database configuration is available in the Configuring Database service section of JOnAS documentation.