JDBC  «Prev  Next »

Lesson 5 Setting up A JDBC data source
Objective Create a data source to be used in later lessons.

Setting up JDBC Data Source

Because most servlet developers use the JDBC-ODBC bridge, this lesson will show you how to create an ODBC data source that the bridge can access. This requires you to have the appropriate ODBC driver installed on your computer.
If you are using Windows, you will have the driver installed.
For instructions on installing the driver on a UNIX system visit this the page displayed below.

Creating Data Source

Setting up DSN (Data Source Name)

Before your program can access the data through the bridge, ODBC must be able to find it. Arranging this is called "Setting up a DSN". DSN stands for Data Source Name. Once a DSN is in place, ODBC accesses the data only through this DSN. That makes it easy to move a database without changing any code, simply by reconfiguring the DSN. The steps that follow illustrate the process on Windows Desktop and Windows server. UNIX users should follow the steps provided with their drivers to set up an Access DSN.
First, you create the database with a database program such as Access or SQL Server. Remember to take note of the file name and the full path to the file, you will need it when you set up the DSN. Use the following simulation to learn the steps involved with setting up a DSN.

1) Text 1 2) Text 2 3) Text 3 4) Text 4 5) Text 5 6) Text 6 7) Text 7 8) Text 8
  1. Begin by opening the Control Panel, by choosing Start, Settings, Control Panel. Find the control panel item called 32-bit ODBC (on NT, it is just called ODBC) and double-click it to launch ODBC.
  2. So that the servlets can see the database, you need to create a System DSN on the same computer that will run your Web server. You need to bring the System DSN tab to the front by clicking the System DSN tab.
  3. Click the Add button on the System DSN tab to add a System DSN.
  4. Here you choose the driver to create a new data source. Notice I have selected the Access driver, which can read and write Access files. Click Finish on the dialog box to move on to creating the new data source
  5. Name your datasource and add a description before connecting this datasource name to a real database. In the Datasource Name field type in javadeploy.com. In the Description field type in "Sample data for Java Servlets course".
    Since I have already created an Access database, click Select to browse to the path of the database
  6. Browse to the location of the database and select the file (I have done this for you). Click OK to return to the Setup dialog.
  7. Click OK to accept your datasource name, description and path.
  8. You can now see the new DSN added to the list. This ends the simulation. Click Exit to return to the lesson.

Setup System DSN
In the next lesson, you will learn where to add connection code to connect to this DSN.

Setting Up JDBC Data Source - Exercise


The following exercise asks you to set up your own data source.
Setting Up JDBC Data Source - Exercise