Java Reference
In-Depth Information
Forbrevity,I'llfocusonlyonthesimpleJDBCapplicationthat'slocatedinthe pro-
grams directory's simple subdirectory. This application runs in either the default
embedded environment or the client/server environment. It creates and connects to a
derbyDB database,introducesatableintothisdatabase,performsinsert/update/select
operations on this table, drops (removes) the table, and disconnects from the database.
Torunthisapplicationintheembeddedenvironment,openacommandwindowand
make sure that the DERBY_HOME and CLASSPATH environment variables have been
setproperly;invoke setEmbeddedCP tosettheclasspath.Assumingthat simple is
thecurrentdirectory,invoke java SimpleApp or java SimpleApp embedded
to run this application. You should observe the following output:
SimpleApp starting in embedded mode
Loaded the appropriate driver
Connected to and created database derbyDB
Created table location
Inserted 1956 Webster
Inserted 1910 Union
Updated 1956 Webster to 180 Grand
Updated 180 Grand to 300 Lakeshore
Verified the rows
Dropped table location
Committed the transaction
Derby shut down normally
SimpleApp finished
This output reveals that an application running in the embedded environment shuts
downthedatabaseenginebeforeexiting.Thisisdonetoperformacheckpointandre-
lease resources. When this shutdown doesn't occur, Java DB notes the absence of the
checkpoint,assumesacrash,andcausesrecoverycodetorunbeforethenextdatabase
connection (which takes longer to complete).
Tip When running SimpleApp (or any other Java DB application) in the em-
bedded environment, you can determine where the database directory will be created
by setting the derby.system.home property. For example, java -
Dderby.system.home=c:\ SimpleApp causes derbyDB tobecreatedinthe
root directory of the C: drive on a Windows platform.
Torunthisapplicationintheclient/serverenvironment,youneedtostartthenetwork
server and run the application in separate command windows.
Search WWH ::




Custom Search