Servlet JDBC Sample

Download

The following sample contains a server definition for basic servlet support, illustrating a simple datasource definition using an included configuration file.

Description

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 8.5.0.0 and later.

Instructions

To run the JDBCApp application:

  1. Extract the sample into the Liberty installation by running the command below from the root of your server installation:
    java -jar JDBCSample.jar
  2. Start the JDBCSample server by running the command below from the bin directory in the Liberty profile installation:
    server run JDBCSample
  3. Confirm the application started by looking for the following message in the log:
    CWWKZ0001I: Application JDBCApp started in XX.XX seconds.
  4. 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).
  5. In your browser, you should see the message
    Text retrieved from database is: myHomeCounty

Notes

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
            • - apps
              • - JDBCApp.war
            • - myConfigDir
              • - myds.xml
            • - server.xml
            • - readme.html
            • - Copyright.txt
            • - bootstrap.properties
        • shared
          • config
            • JDBCSampleDerbyLibs.xml (shared Derby Library configuration for JDBC)
          • resources
            • JDBCSampleDerbyLibs (pre-requisite Derby Library – downloadable during installation)
  • iris

    The download link was broken. Please update

    • http://ibmdw.net/ dW

      Can you try the link again? It is working for us.