Lesson 3: Set up the database connection
In this lesson, you will connect your project to the database that you imported in the previous lesson.
About this task
As explained in a previous lesson, WebSphere® Application Server uses database connection information in the EAR project. Tomcat uses database connection information in the web project. Thus, the database connection steps differ for each server.
Creating the connection
About this task
Procedure
Lesson checkpoint
In this lesson, you set up a database connection for the project.
Procedure
- EGL set the values of certain database-related build descriptor options, as explained earlier in the lesson.
- EGL created a JNDI name to
use as a name for the connection. By default, the JNDI name created for your project
is
jdbc/EGLDerbyDB, based on the name of the database. - EGL added a resource reference to that JNDI name in the EGLWeb
project's web deployment descriptor, WebContent\WEB-INF\web.xml. Now the EGLWeb project can use the data
source defined in the EAR project, using the JNDI name. The editor looks very
different depending on the version of the application server you use. The following
example shows the editor for WebSphere® Application Server Version 8.

If you are using Tomcat, your project doesn't have an EAR project, so EGL added a contexts file to the web project that gives the information for the connection. The contexts file performs essentially the same task as the information in the deployment descriptors: it associates the JNDI name with the location of the database and other information that the server needs to connect to it. The connection is valid only for this project.


