Servlet JDBC Sample

The ServletJDBCEngine sample contains a server definition for basic servlet support, and illustrates a simple datasource definition using an included configuration file. It uses Apache Derby (an open source relational database). Also included is a servlet which gets a connection to the database using the defined datasource, creates a table, inserts some data, retrieves the data, and prints the data out to the browser

This sample can be installed onto runtime versions and later.

Installation Instructions

Online installation (requires or later):

  1. Install the sample by running the command below from the bin directory of your server installation:
    installUtility install JDBCSample

Any missing features required by the server will be installed for you.

Offline installation:

  1. Download the JDBCSample.jar using the download button at the top of the page and place it in the root of your server installation.
  2. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar JDBCSample.jar

Any missing features required by the server will need to be installed separately.

Running The Application

To run the JDBCApp application:

  1. Start the JDBCSample server by running the command below from the bin directory in the Liberty profile installation:
    server run JDBCSample
  2. Confirm the application started by looking for the following message in the log:
    CWWKZ0001I: Application JDBCApp started in XX.XX seconds.
  3. In your browser, enter the URL for the application: http://localhost:9120/JDBCApp/ (where port 9120 assumes the httpEndpoint provided in the sample server.xml has not been modified).
  4. In your browser, you should see the message
    Text retrieved from database is: myHomeCounty


The JDBCApp.war file contains the source and binaries for the application, and can be used to import it to Eclipse.

The created database is stored in usr/shared/resources/data/exampleDB as specified by the 'databaseName' property of the datasource.

This sample does not include the open source dependencies. The installer will provide a list of the open source pre-requisite libraries and where they can be downloaded from. To help obtaining these libraries, the installer provides the option to download them on your behalf.

Sample Structure

  • wlp
    • usr
      • servers
        • JDBCSample
          • Copyright.txt
          • apps
            • JDBCApp.war
          • lafiles
            • LA_en
            • LI_en
          • myConfigDir
            • myds.xml
          • readme.html
          • server.xml
      • shared
        • config
          • JDBCSampleDerbyLibs.xml
        • resources
          • JDBCSampleDerbyLibs
            • derby-