The following sample contains a server definition for basic servlet support, illustrating a simple datasource definition using an included configuration file.
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 22.214.171.124 and later.
To run the JDBCApp application:
- Extract the sample into the Liberty installation by running the command below from the root of your server installation:
java -jar JDBCSample.jar
- Start the JDBCSample server by running the command below from the
bindirectory in the Liberty profile installation:
server run JDBCSample
- Confirm the application started by looking for the following message in the log:
CWWKZ0001I: Application JDBCApp started in XX.XX seconds.
- 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).
- In your browser, you should see the message
Text retrieved from database is: myHomeCounty
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.
- - wlp
- - usr
- - servers
- - JDBCSample
- - apps
- - JDBCApp.war
- - myConfigDir
- - myds.xml
- - server.xml
- - readme.html
- - Copyright.txt
- - bootstrap.properties
- JDBCSampleDerbyLibs.xml (shared Derby Library configuration for JDBC)
- JDBCSampleDerbyLibs (pre-requisite Derby Library – downloadable during installation)