background image
<< Run a JDBC program using the embedded driver | Define key variables and objects >>
<< Run a JDBC program using the embedded driver | Define key variables and objects >>

The WwdEmbedded program

Getting Started with Derby
28
Operating
System
Command
UNIX (Korn Shell)
cp $DERBY_HOME/demo/programs/workingwithderby/* .
export CLASSPATH=$DERBY_HOME/lib/derby.jar:.
Windows
copy %DERBY_HOME%\demo\programs\workingwithderby\*
.
set CLASSPATH=%DERBY_HOME%\lib\derby.jar;.
> 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.
2. 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.
3. 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.
java WwdEmbedded
org.apache.derby.jdbc.EmbeddedDriver loaded.
Connected to database jdbcDemoDB
. . . . creating table WISH_LIST
Enter wish-list item (enter exit to end):
a peppermint stick
__________________________________________________
On 2011-03-02 17:41:52.531 I wished for a peppermint stick
__________________________________________________
Enter wish-list item (enter exit to end):
a long vacation
__________________________________________________
On 2011-03-02 17:41:52.531 I wished for a peppermint stick
On 2011-03-02 17:42:03.248 I wished for a long vacation
__________________________________________________
Enter wish-list item (enter exit to end):
exit
Closed connection
Database shut down normally
Getting Started With Derby JDBC program ending.
The WwdEmbedded program
This section describes the
WwdEmbedded.java
program, highlighting details specific to
accessing a Derby database from a JDBC program.
Most of the code related to the database activities performed is included in this section,
but you might find it helpful to open the program file and follow along in a text viewer or
editor. The SECTION NAMES referred to in this section can be found in the comments