Sun ONE logo      Previous      Contents      Index      Next     

Sun ONE Web Server 6.1 Getting Started Guide

Chapter 7
Setting Up Database Connectivity

Web applications leverage the benefits of the component-based Java™ 2 Platform, Enterprise Edition (J2EE™) technology, which include scalability and speed.

Web components, Java Servlets or JSP pages, provide the dynamic extension capabilities for Sun ONE Web Server 6.1. Servlets and JSP pages are supported by the services of a runtime platform called a web container. The web container provides services such as request dispatching, security, and concurrency. It also gives web components access to APIs such as naming, datasources, and e-mail.

In this chapter, we will work with a sample application that uses the Java™ Database Connectivity (JDBC™) API to record greetings to a database.

In this chapter you will define the necessary JDBC-related settings in the web server environment prior to deploying and exercising the sample.

Install and Configure the JDBC driver

JDBC configuration involves setting up a JDBC driver, defining a JDBC connection pool, and registering the JDBC resources used by your application.

A JDBC driver must be configured in the classpath of the web server before you can exercise applications that use JDBC. In this example, we use the PointBase JDBC driver.

To install and configure PointBase for use with the sample applications, follow these steps:

Download and Install PointBase Server and Client Products

Download the PointBase evaluation software from

Install at least the PointBase Server and Client products on your system. The PointBase Client product includes the PointBase Type 4 JDBC driver.

Add PointBase Type 4 JDBC Driver to the Web Server's Classpath
  1. Open the server-instance/config/server.xml file of the web server instance. Add the location of the PointBase driver in the classpathsuffix.
  2. You can find the JDBC driver under <pointbase_install_dir>/lib/.

    The driver is named pbclientnn.jar where nn represents the version of PointBase.

  3. Restart the web server to make the server aware of the driver.

Alternatively, you can specify the location of the PointBase driver in the Classpath Suffix field in the web server’s configuration:

  1. Access the web server instance's Java tab -> Java Path Settings page to make this change.
  2. If a PointBase JDBC driver is already configured in the Classpath Suffix field, replace it with the path to the newly installed driver.

  3. Once you’ve changed the Classpath Suffix field, apply the changes and restart the web server instance.
Start the Database Server

The database server can be easily started by performing one of the following actions:

On Windows Platforms:

Execute: <pointbase_install_dir>/tools/server/startserver.bat

On UNIX Platforms:

Execute: <pointbase_install_dir>/tools/server/

Once you execute the startup script, you will see the following text in either a command window or at the UNIX terminal prompt:

Server started, listening on port 9092, display level: 0 ...

Create a Database and Table

For information about creating and maintaining a database using PointBase, refer to the database documentation. After you have created a database, you need to use the following script to create the table 'Greeting', which will record application entries: <install_root>/plugins/java/samples/webapps/jdbc/simple/src/sql/jdbc-simple-pb.sql

Define the JDBC Connection Pool

Before running the sample application, you need to define a suitable JDBC connection pool that maps to the PointBase database server and a JDBC resource that associates the JDBC references made in the sample application to the JDBC connection pool definition.

  1. Through a web browser, access the administration server interface. (You might have to start the administration server if it is not running).
  2. Select the Java tab in the server instance and click JDBC Connection Pools

  3. Figure showing the JDBC Connection Pools page.

  4. Click New, and select the JDBC driver, as shown below:

  5. Figure showing the New JDBC Connection Pool page where you can select the JDBC driver.

  6. In the Add New JDBC Connection Pools page, we’ve specified the following settings and left the rest unmodified:
    • jdbc-simple-pool as the name of the new connection pool.
    • jdbc:pointbase:server://localhost/sample as database name
    • PBPUBLIC as the user name
    • PBPUBLIC as the password
    • Transaction Isolation set to read-committed

    • Figure showing the New JDBC Connection Pool page where you can configure the parameters for a new connection pool.

  7. Click OK and then Apply to save and apply your changes.
Define the JDBC Resource

Now that the JDBC connection pool definition has been created, you are ready to define a JDBC resource and associate it with the connection pool entry.

  1. Under the Java tab of the server instance, click the JDBC Resources link.
  2. Click the New button to define a new resource entry.

  3. Figure showing the JDBC Resources page.

  4. Since the sun-web.xml file of the sample web application refers to the JNDI Name of the resource as "jdbc/jdbc-simple", you need to define the JDBC resource with this same JNDI name.
  5. Set the fields to the following values and click the OK button to define the resource:

    Figure showing the New JDBC Resource page.

  6. Click OK and Apply to save and apply your changes.

After you’ve set up database connectivity, you’re ready to deploy the jdbc-simple sample web application that uses these newly created JDBC resources. You can find this sample application at the following location:

install_root/plugins/java/samples/webapps/jdbc/simple/jdbc-simple.w ar

To deploy this sample application, follow the steps outlined in Chapter 6, "Running Java Web Applications On Your Server."

Previous      Contents      Index      Next     

Copyright 2004 Sun Microsystems, Inc. All rights reserved.