Activity 3: Run a JDBC program using the embedded driver

This activity loads the Derby database
engine using a simple Java JDBC program.

This activity assumes that you have opened a command window and navigated
to the DERBYTUTOR directory.

JDBC is the Java Database Connectivity API and is also the native
API for Derby. The program
uses the embedded driver to create the jdbcDemoDB database
(if the database does not exist) and then connect to the database. You can
then populate a table within the database with text. The program demonstrates
some basic JDBC processing along with related error handling.

The Java
compiler and runtime use the classpath, specified by the CLASSPATH environment
variable, to locate the binary files (jar files and class files) that are
needed to run Derby and
other Java applications. Before performing this activity, you need to set
the classpath and compile the WwdEmbedded.java program.

Copy the program files into the DERBYTUTOR directory
and set the CLASSPATH environment variable, as shown in the
following table. See
Installing Java DB for information
on obtaining the demos.

Table 1. Commands to copy the program files and set the CLASSPATH
environment variable. This table lists the commands to copy the program files into the DERBYTUTOR directory and set the CLASSPATH environment variable on UNIX and Windows systems.

Important: Include the dot (.)
at the end of each command so that your current working directory is included
in the classpath and the files are copied to the correct location.

Compile the program source files.
The sample program is contained in two source files:
WwdEmbedded.java and WwdUtils.java.
Issue the following command to compile both at the same time:

javac WwdEmbedded.java WwdUtils.java

Important: A command prompt appears if the compilation
is successful. The binary files WwdEmbedded.class and
WwdUtils.class are created.
If an error message appears, verify that the JDK is properly installed.

Run the program. The WwdEmbedded.java program populates
a table with wish-list items. The program prompts you for text input (up to
32 characters), stores the text input in a database table, and then lists
the items stored in the table. The program continues to ask for wish-list
items until the you type the command exit or a problem is
encountered. Some basic information on program progress is displayed at the
beginning and the end of the program.