background image
<< Self-study tutorial for users new to Derby | Creating a Derby database and running SQL statements >>
<< Self-study tutorial for users new to Derby | Creating a Derby database and running SQL statements >>

Run SQL using the embedded driver

Getting Started with Derby
22
Load the Derby database engine from a simple Java JDBC program. Use the
embedded driver to create the database
jdbcDemoDB
and the
WISH_LIST
table.
Populate the table with text entered from the keyboard, then view a list of the records
in the table. Walk through the code to understand the basic structure of a JDBC
program that accesses a Derby database. The
CLASSPATH
variable and connection
URL attribute
;shutdown=true
are introduced.
Activity 4:
Modify the Java JDBC program to load the client driver and connect to the Derby
Network Server. Compile the altered program and test that the program operates as it
did in the previous activity.
Activity 1: Run SQL using the embedded driver
In this activity, you will use the embedded driver to load the Derby database engine,
create and connect to a database, and use some basic SQL statements.
To run SQL using the embedded driver:
1.
Create a directory and copy scripts into the directory
2.
Create a Derby database and run SQL statements
Creating a directory and copying scripts into the directory
To help you complete this activity, you must create a directory and copy several scripts
into the new directory. You will use these scripts to quickly add tables and data to a new
Derby database.
Tip: A command prompt appears after each command is run. If an error occurs, verify
the syntax and retype the command.
1. Open a command window and change to a directory where you want to store the
files that you create during the self-study tutorial activities.
2. Create the
DERBYTUTOR
directory, as shown in the following table.
DERBYTUTOR
will be your working directory for this activity.
Table 9.
Command to create the
DERBYTUTOR
directory
Operating
System
Command
UNIX (Korn Shell)
mkdir DERBYTUTOR
Windows
md DERBYTUTOR
3. Change to the
DERBYTUTOR
directory, as shown in the following table.
Table 10.
Command to change to the
DERBYTUTOR
directory
Operating
System
Command
UNIX (Korn Shell)
cd DERBYTUTOR
Windows
cd DERBYTUTOR
4. Copy the SQL scripts from the Derby
demo\programs\toursdb
subdirectory
into the
DERBYTUTOR
directory, as shown in the following table. You will use these
scripts to create tables and add data to a new database,
toursdb
.
Table 11.
Command to copy the SQL scripts