How Ebase Accesses Databases

 

Documentation home

J2EE notes 1

Add a database connection (using the web application context) 1

 

See also: Database Connections

 

These notes are intended for someone configuring a database connection with an application server other than Tomcat, and with configuration knowledge of the J2EE application server under which Ebase is installed. If you experience difficulties, please contact Ebase Technology for support.

 

J2EE notes

 

According to the J2EE specification, the recommended technique for a J2EE application such as Ebase to access a database is via the web application context. This works as follows: the application provides a list of database resources that it needs to access in resource reference entries within its .war file. When the application is installed, these resource references are mapped to the "real" resource connections defined to the J2EE application server. However, while this technique is recommended by the specification, it is not mandated. Application servers differ in their requirements for adding a database connection to an application after it has been installed; some allow this to be done by editing configuration files, whereas others require that the .war file is changed and then re-installed.

 

Because of these differences, Ebase attempts a number of different options when looking up a datasource connection. When a connection is first made, Ebase tries these options in the following order:

 

  1. Look up the database connection in the web application context using name jdbc/RESOURCE NAME (as recommended in the J2EE specification).
  2. Look up the database connection directly using name jdbc/RESOURCE NAME (this is how it used to work prior to the introduction of the web application context).
  3. Look up the database connection directly using name prefix/RESOURCE NAME where prefix is supplied by the jndi_naming_prefix.  This technique should only be used if the above two options cannot be implemented.

 

where RESOURCE NAME is the datasource id taken from the Ebase Database Connection which is configured with connection type: Pooled connection configured in application server.

 

Add a database connection (using the web application context)

 

This is the recommended option. The details for each step are dependent on the application server you are using.

 

1.      Add the database to the web application context. Add a definition like the one below to the web.xml file in the Web-Inf directory for the Ebase web application.

 

<resource-ref id="ResourceRef_1">

<description>Your database</description>

<res-ref-name>jdbc/YOURDBNAME</res-ref-name>

<res-type>javax.sql.XADataSource</res-type>

<res-auth>Container</res-auth>

</resource-ref>

 

Ensure that the prefix jdbc/ is used in the resource reference name.

 

2.      Add the datasource connection definition to the application server. Details vary according to the application server.

 

Note: if creating a connection to a MySQL database, include the parameter 'autoReconnect=true' in the JDBC URL. Failure to do this can lead to lost connections reported as SocketException errors.

 

3.      Map the web application resource reference to the datasource definition. Details vary according to the application server.

 

Note that some application servers do not give you access to the xml files to allow you to complete the third step. You may need to expand and modify the supplied UFS.war file to add the resource definition in step 1 above, and then re-deploy this into your application server.