Run a JDBC program using the embedded driver
Getting Started with Derby
27
1 row selected
10. Exit
ij
.
exit;
11. Shut down the Derby Network Server, as shown in the following table.
Table 16.
Command to shut down the Network Server
Operating
System
Command
UNIX (Korn Shell)
java -jar $DERBY_HOME/lib/derbyrun.jar server
shutdown
Wed Mar 02 17:29:44 EST 2011 : Apache Derby
Network Server - 10.8.0.0 - (1076370) shutdown
Windows
java -jar %DERBY_HOME%\lib\derbyrun.jar server
shutdown
Wed Mar 02 17:29:44 EST 2011 : Apache Derby
Network Server - 10.8.0.0 - (1076370) shutdown
The server shutdown confirmation appears in both command windows.
Activity notes
The client connection URL contains network information (hostname and portnumber)
not found in the URL for an embedded connection. This information tells the client driver
the location of the Network Server. The client driver sends requests to and receives
responses from the Network Server.
In this activity the Derby database engine is embedded in the Network Server and returns
data to the
ij
client (a client/server configuration). In contrast, establishing a connection
using an embedded URL (one without
//localhost:1527/
) would have caused the
Derby engine to be embedded in the
ij
application (an embedded configuration).
In this configuration, multiple client programs can connect to the Network Server and
access the database simultaneously. (This activity does not demonstrate this capability.)
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.
1. Copy the program files into the
DERBYTUTOR
directory and set the
CLASSPATH
environment variable, as shown in the following table.
Table 17.
Commands to copy the program files and set the
CLASSPATH
environment variable