Modified: incubator/derby/code/trunk/java/demo/nserverdemo/readme.html URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/nserverdemo/readme.html?rev=164630&r1=164629&r2=164630&view=diff ============================================================================== --- incubator/derby/code/trunk/java/demo/nserverdemo/readme.html (original) +++ incubator/derby/code/trunk/java/demo/nserverdemo/readme.html Mon Apr 25 12:29:37 2005 @@ -1,26 +1,26 @@ - - - -Example Programs - - - - -

Overview

-

The following example scenarios show you how to obtain an embedded connection and client connections using the Network Server to connect to the same database.

- -

An embedded connection is a connection to a database that is booted in the same JVM as the application. This connection can be obtained after the Derby Embedded driver is booted. The URL prefix is jdbc:derby:

- -

Client applications that require a database connection across the network use the network server protocol (DRDA) to connect to the Network Server. This type of connection is referred to as a client connection. The URL prefix is jdbc:derby:net:

- - - - + + + +Example Programs + + + + +

Overview

+

The following example scenarios show you how to obtain an embedded connection and client connections using the Network Server to connect to the same database.

+ +

An embedded connection is a connection to a database that is booted in the same JVM as the application. This connection can be obtained after the Derby Embedded driver is booted. The URL prefix is jdbc:derby:

+ +

Client applications that require a database connection across the network use the network server protocol (DRDA) to connect to the Network Server. This type of connection is referred to as a client connection. The URL prefix is jdbc:derby:net:

+ + + + Propchange: incubator/derby/code/trunk/java/demo/nserverdemo/readme.html ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/derby/code/trunk/java/demo/nserverdemo/simpleserversample.html URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/nserverdemo/simpleserversample.html?rev=164630&r1=164629&r2=164630&view=diff ============================================================================== --- incubator/derby/code/trunk/java/demo/nserverdemo/simpleserversample.html (original) +++ incubator/derby/code/trunk/java/demo/nserverdemo/simpleserversample.html Mon Apr 25 12:29:37 2005 @@ -1,153 +1,153 @@ - - - - - -Derby Network Server Simple sample program - - - - -

Simple Derby Network Server Example

- -

Overview

- -

The primary purpose of this example is to demonstrate how to obtain an embedded -connection and client connections using the Network Server to the same -database. This program shows how to use either the DriverManager or a -DataSource to obtain client connections.

- -

In order for a database to be consistent, only one JVM is allowed to access -it at a time. The embedded driver is loaded when the Network Server is started. -Hence, the JVM that starts the Network Server can get an embedded connection to -the same database that Network Server is accessing to serve the clients from -other JVMs. This solution allows you to take advantage of the performance -benefits of the embedded driver as well as allow for client connections from other -JVMs to connect to the same database.

- -

In this example, the following two programs show how to setup the server and -client programs when interacting with the Network Server.

- -

SimpleNetworkServerSample.java: -This program starts the Derby Network Server as well as the embedded -driver and waits for clients to connect.

- -

SimpleNetworkClientSample.java: -This is the client program that interacts with the Derby Network Server -from another JVM.

- -

SimpleNetworkServerSample program

- -

In particular, this program:

- - - -

The following files should be installed in the %DERBY_INSTALL%\demo\programs\nserverdemo\ directory in -order to run this sample program:

- - - -

How to run the SimpleNetworkServerSample program

- -

To run this simple Derby Network Server sample program:

- -
    -
  1. Open a command prompt and change directories to the %DERBY_INSTALL%\demo\programs\nserverdemo - directory, where %DERBY_INSTALL% is the directory - where you installed Derby.
  2. -
  3. Set the CLASSPATH to include the following jar files in order to run this - program.
  4. - - -
  5. Test the CLASSPATH settings by running the following java command: - -
    java org.apache.derby.tools.sysinfo
    - -

    This command will show the Derby jar files that are in the CLASSPATH.

  6. - -
  7. Once you have set up your environment correctly, execute the application from the
    %DERBY_INSTALL%\demo\programs\nserverdemo directory: - -
    java SimpleNetworkServerSample
    -
-

You should receive output similar to the following if the program runs successfully:

-Starting Network Server
Testing if Network Server is up and running!
Derby Network Server now running
Got an embedded connection.
Testing embedded connection by executing a sample query
number of rows in sys.systables = 16

While my app is busy with embedded work, ij might connect like this:

$ java -Dij.user=me -Dij.password=pw -Dij.protocol=jdbc:derby:net://localhost:1527/ org.apache.derby.tools.ij
ij> connect 'NSSimpleDB:retrieveMessagesFromServerOnGetMessage=true;';
Watch that punctuation. Put a ':' before the jcc
attributes and a ';' after each one (even the last).


Clients can continue to connect:
Press [Enter] to stop Server
- -

Running this program will also create new directories and files:

- - - - -

Example of a Client connecting to the Network Server

- -

SimpleNetworkClientSample program

- -

This program:

- - - -

The following files should be installed in the %DERBY_INSTALL%\demo\programs\nserverdemo\ directory in order to run this sample program:

- - -

How to run the SimpleNetworkClientSample program

- -

To connect to the Network Server that has been started as part of the SimpleNetworkServerSample program:

- -
    -
  1. Open a command prompt and change directories to the %DERBY_INSTALL%\demo\programs\nserverdemo directory, where %DERBY_INSTALL% is the directory where you installed Derby.
  2. -
  3. Clients of Derby Network Server only need the following jar files in the CLASSPATH in order to connect to the Network Server. Set the CLASSPATH to include the following jar files: -
  4. -
  5. Once you have set up your environment correctly, execute the -application from the
    %DERBY_INSTALL%\demo\programs\nserverdemo\ directory: -
    java SimpleNetworkClientSample
    -
  6. -
- -

You should receive output similar to the following if the program runs -successfully:

- -Starting Sample client program
Got a client connection via the DriverManager.
connection from datasource; getDriverName = IBM DB2 JDBC Universal Driver Architecture
Got a client connection via a DataSource.
Testing the connection obtained via DriverManager by executing a sample query
number of rows in sys.systables = 16
Testing the connection obtained via a DataSource by executing a sample query
number of rows in sys.systables = 16
Goodbye!
- - - - + + + + + +Derby Network Server Simple sample program + + + + +

Simple Derby Network Server Example

+ +

Overview

+ +

The primary purpose of this example is to demonstrate how to obtain an embedded +connection and client connections using the Network Server to the same +database. This program shows how to use either the DriverManager or a +DataSource to obtain client connections.

+ +

In order for a database to be consistent, only one JVM is allowed to access +it at a time. The embedded driver is loaded when the Network Server is started. +Hence, the JVM that starts the Network Server can get an embedded connection to +the same database that Network Server is accessing to serve the clients from +other JVMs. This solution allows you to take advantage of the performance +benefits of the embedded driver as well as allow for client connections from other +JVMs to connect to the same database.

+ +

In this example, the following two programs show how to setup the server and +client programs when interacting with the Network Server.

+ +

SimpleNetworkServerSample.java: +This program starts the Derby Network Server as well as the embedded +driver and waits for clients to connect.

+ +

SimpleNetworkClientSample.java: +This is the client program that interacts with the Derby Network Server +from another JVM.

+ +

SimpleNetworkServerSample program

+ +

In particular, this program:

+ + + +

The following files should be installed in the %DERBY_INSTALL%\demo\programs\nserverdemo\ directory in +order to run this sample program:

+ + + +

How to run the SimpleNetworkServerSample program

+ +

To run this simple Derby Network Server sample program:

+ +
    +
  1. Open a command prompt and change directories to the %DERBY_INSTALL%\demo\programs\nserverdemo + directory, where %DERBY_INSTALL% is the directory + where you installed Derby.
  2. +
  3. Set the CLASSPATH to include the following jar files in order to run this + program.
  4. + + +
  5. Test the CLASSPATH settings by running the following java command: + +
    java org.apache.derby.tools.sysinfo
    + +

    This command will show the Derby jar files that are in the CLASSPATH.

  6. + +
  7. Once you have set up your environment correctly, execute the application from the
    %DERBY_INSTALL%\demo\programs\nserverdemo directory: + +
    java SimpleNetworkServerSample
    +
+

You should receive output similar to the following if the program runs successfully:

+Starting Network Server
Testing if Network Server is up and running!
Derby Network Server now running
Got an embedded connection.
Testing embedded connection by executing a sample query
number of rows in sys.systables = 16

While my app is busy with embedded work, ij might connect like this:

$ java -Dij.user=me -Dij.password=pw -Dij.protocol=jdbc:derby:net://localhost:1527/ org.apache.derby.tools.ij
ij> connect 'NSSimpleDB:retrieveMessagesFromServerOnGetMessage=true;';
Watch that punctuation. Put a ':' before the jcc
attributes and a ';' after each one (even the last).


Clients can continue to connect:
Press [Enter] to stop Server
+ +

Running this program will also create new directories and files:

+ + + + +

Example of a Client connecting to the Network Server

+ +

SimpleNetworkClientSample program

+ +

This program:

+ + + +

The following files should be installed in the %DERBY_INSTALL%\demo\programs\nserverdemo\ directory in order to run this sample program:

+ + +

How to run the SimpleNetworkClientSample program

+ +

To connect to the Network Server that has been started as part of the SimpleNetworkServerSample program:

+ +
    +
  1. Open a command prompt and change directories to the %DERBY_INSTALL%\demo\programs\nserverdemo directory, where %DERBY_INSTALL% is the directory where you installed Derby.
  2. +
  3. Clients of Derby Network Server only need the following jar files in the CLASSPATH in order to connect to the Network Server. Set the CLASSPATH to include the following jar files: +
  4. +
  5. Once you have set up your environment correctly, execute the +application from the
    %DERBY_INSTALL%\demo\programs\nserverdemo\ directory: +
    java SimpleNetworkClientSample
    +
  6. +
+ +

You should receive output similar to the following if the program runs +successfully:

+ +Starting Sample client program
Got a client connection via the DriverManager.
connection from datasource; getDriverName = IBM DB2 JDBC Universal Driver Architecture
Got a client connection via a DataSource.
Testing the connection obtained via DriverManager by executing a sample query
number of rows in sys.systables = 16
Testing the connection obtained via a DataSource by executing a sample query
number of rows in sys.systables = 16
Goodbye!
+ + + + Propchange: incubator/derby/code/trunk/java/demo/nserverdemo/simpleserversample.html ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/derby/code/trunk/java/demo/readme.html URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/readme.html?rev=164630&r1=164629&r2=164630&view=diff ============================================================================== --- incubator/derby/code/trunk/java/demo/readme.html (original) +++ incubator/derby/code/trunk/java/demo/readme.html Mon Apr 25 12:29:37 2005 @@ -1,15 +1,15 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + Propchange: incubator/derby/code/trunk/java/demo/readme.html ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/derby/code/trunk/java/demo/simple/SimpleApp.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/simple/SimpleApp.java?rev=164630&r1=164629&r2=164630&view=diff ============================================================================== --- incubator/derby/code/trunk/java/demo/simple/SimpleApp.java (original) +++ incubator/derby/code/trunk/java/demo/simple/SimpleApp.java Mon Apr 25 12:29:37 2005 @@ -1,244 +1,244 @@ -/* - - Derby - Class SimpleApp - - Copyright 2001, 2004 The Apache Software Foundation or its licensors, as applicable. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - */ - -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -import java.util.Properties; - - -/** - * This sample program is a minimal JDBC application showing - * JDBC access to Derby. - * - * Instructions for how to run this program are - * given in example.html. - * - * Derby applications can run against Derby running in an embedded - * or a client/server framework. When Derby runs in an embedded framework, - * the Derby application and Derby run in the same JVM. The application - * starts up the Derby engine. When Derby runs in a client/server framework, - * the application runs in a different JVM from Derby. The application only needs - * to start the client driver, and the connectivity framework provides network connections. - * (The server must already be running.) - * - *

When you run this application, give one of the following arguments: - * * embedded (default, if none specified) - * * jccjdbcclient (if Derby is running embedded in the JCC Server framework) - * - * @author janet - */ -public class SimpleApp -{ - /* the default framework is embedded*/ - public String framework = "embedded"; - public String driver = "org.apache.derby.jdbc.EmbeddedDriver"; - public String protocol = "jdbc:derby:"; - - public static void main(String[] args) - { - new SimpleApp().go(args); - } - - void go(String[] args) - { - /* parse the arguments to determine which framework is desired*/ - parseArguments(args); - - System.out.println("SimpleApp starting in " + framework + " mode."); - - try - { - /* - The driver is installed by loading its class. - In an embedded environment, this will start up Derby, since it is not already running. - */ - Class.forName(driver).newInstance(); - System.out.println("Loaded the appropriate driver."); - - Connection conn = null; - Properties props = new Properties(); - props.put("user", "user1"); - props.put("password", "user1"); - - /* - The connection specifies create=true to cause - the database to be created. To remove the database, - remove the directory derbyDB and its contents. - The directory derbyDB will be created under - the directory that the system property - derby.system.home points to, or the current - directory if derby.system.home is not set. - */ - conn = DriverManager.getConnection(protocol + - "derbyDB;create=true", props); - - System.out.println("Connected to and created database derbyDB"); - - conn.setAutoCommit(false); - - /* - Creating a statement lets us issue commands against - the connection. - */ - Statement s = conn.createStatement(); - - /* - We create a table, add a few rows, and update one. - */ - s.execute("create table derbyDB(num int, addr varchar(40))"); - System.out.println("Created table derbyDB"); - s.execute("insert into derbyDB values (1956,'Webster St.')"); - System.out.println("Inserted 1956 Webster"); - s.execute("insert into derbyDB values (1910,'Union St.')"); - System.out.println("Inserted 1910 Union"); - s.execute( - "update derbyDB set num=180, addr='Grand Ave.' where num=1956"); - System.out.println("Updated 1956 Webster to 180 Grand"); - - s.execute( - "update derbyDB set num=300, addr='Lakeshore Ave.' where num=180"); - System.out.println("Updated 180 Grand to 300 Lakeshore"); - - /* - We select the rows and verify the results. - */ - ResultSet rs = s.executeQuery( - "SELECT num, addr FROM derbyDB ORDER BY num"); - - if (!rs.next()) - { - throw new Exception("Wrong number of rows"); - } - - if (rs.getInt(1) != 300) - { - throw new Exception("Wrong row returned"); - } - - if (!rs.next()) - { - throw new Exception("Wrong number of rows"); - } - - if (rs.getInt(1) != 1910) - { - throw new Exception("Wrong row returned"); - } - - if (rs.next()) - { - throw new Exception("Wrong number of rows"); - } - - System.out.println("Verified the rows"); - - s.execute("drop table derbyDB"); - System.out.println("Dropped table derbyDB"); - - /* - We release the result and statement resources. - */ - rs.close(); - s.close(); - System.out.println("Closed result set and statement"); - - /* - We end the transaction and the connection. - */ - conn.commit(); - conn.close(); - System.out.println("Committed transaction and closed connection"); - - /* - In embedded mode, an application should shut down Derby. - If the application fails to shut down Derby explicitly, - the Derby does not perform a checkpoint when the JVM shuts down, which means - that the next connection will be slower. - Explicitly shutting down Derby with the URL is preferred. - This style of shutdown will always throw an "exception". - */ - boolean gotSQLExc = false; - - if (framework.equals("embedded")) - { - try - { - DriverManager.getConnection("jdbc:derby:;shutdown=true"); - } - catch (SQLException se) - { - gotSQLExc = true; - } - - if (!gotSQLExc) - { - System.out.println("Database did not shut down normally"); - } - else - { - System.out.println("Database shut down normally"); - } - } - } - catch (Throwable e) - { - System.out.println("exception thrown:"); - - if (e instanceof SQLException) - { - printSQLError((SQLException) e); - } - else - { - e.printStackTrace(); - } - } - - System.out.println("SimpleApp finished"); - } - - static void printSQLError(SQLException e) - { - while (e != null) - { - System.out.println(e.toString()); - e = e.getNextException(); - } - } - - private void parseArguments(String[] args) - { - int length = args.length; - - for (int index = 0; index < length; index++) - { - if (args[index].equalsIgnoreCase("jccjdbcclient")) - { - framework = "jccjdbc"; - driver = "com.ibm.db2.jcc.DB2Driver"; - protocol = "jdbc:derby:net://localhost:1527/"; - } - } - } -} +/* + + Derby - Class SimpleApp + + Copyright 2001, 2004 The Apache Software Foundation or its licensors, as applicable. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import java.util.Properties; + + +/** + * This sample program is a minimal JDBC application showing + * JDBC access to Derby. + * + * Instructions for how to run this program are + * given in example.html. + * + * Derby applications can run against Derby running in an embedded + * or a client/server framework. When Derby runs in an embedded framework, + * the Derby application and Derby run in the same JVM. The application + * starts up the Derby engine. When Derby runs in a client/server framework, + * the application runs in a different JVM from Derby. The application only needs + * to start the client driver, and the connectivity framework provides network connections. + * (The server must already be running.) + * + *

When you run this application, give one of the following arguments: + * * embedded (default, if none specified) + * * jccjdbcclient (if Derby is running embedded in the JCC Server framework) + * + * @author janet + */ +public class SimpleApp +{ + /* the default framework is embedded*/ + public String framework = "embedded"; + public String driver = "org.apache.derby.jdbc.EmbeddedDriver"; + public String protocol = "jdbc:derby:"; + + public static void main(String[] args) + { + new SimpleApp().go(args); + } + + void go(String[] args) + { + /* parse the arguments to determine which framework is desired*/ + parseArguments(args); + + System.out.println("SimpleApp starting in " + framework + " mode."); + + try + { + /* + The driver is installed by loading its class. + In an embedded environment, this will start up Derby, since it is not already running. + */ + Class.forName(driver).newInstance(); + System.out.println("Loaded the appropriate driver."); + + Connection conn = null; + Properties props = new Properties(); + props.put("user", "user1"); + props.put("password", "user1"); + + /* + The connection specifies create=true to cause + the database to be created. To remove the database, + remove the directory derbyDB and its contents. + The directory derbyDB will be created under + the directory that the system property + derby.system.home points to, or the current + directory if derby.system.home is not set. + */ + conn = DriverManager.getConnection(protocol + + "derbyDB;create=true", props); + + System.out.println("Connected to and created database derbyDB"); + + conn.setAutoCommit(false); + + /* + Creating a statement lets us issue commands against + the connection. + */ + Statement s = conn.createStatement(); + + /* + We create a table, add a few rows, and update one. + */ + s.execute("create table derbyDB(num int, addr varchar(40))"); + System.out.println("Created table derbyDB"); + s.execute("insert into derbyDB values (1956,'Webster St.')"); + System.out.println("Inserted 1956 Webster"); + s.execute("insert into derbyDB values (1910,'Union St.')"); + System.out.println("Inserted 1910 Union"); + s.execute( + "update derbyDB set num=180, addr='Grand Ave.' where num=1956"); + System.out.println("Updated 1956 Webster to 180 Grand"); + + s.execute( + "update derbyDB set num=300, addr='Lakeshore Ave.' where num=180"); + System.out.println("Updated 180 Grand to 300 Lakeshore"); + + /* + We select the rows and verify the results. + */ + ResultSet rs = s.executeQuery( + "SELECT num, addr FROM derbyDB ORDER BY num"); + + if (!rs.next()) + { + throw new Exception("Wrong number of rows"); + } + + if (rs.getInt(1) != 300) + { + throw new Exception("Wrong row returned"); + } + + if (!rs.next()) + { + throw new Exception("Wrong number of rows"); + } + + if (rs.getInt(1) != 1910) + { + throw new Exception("Wrong row returned"); + } + + if (rs.next()) + { + throw new Exception("Wrong number of rows"); + } + + System.out.println("Verified the rows"); + + s.execute("drop table derbyDB"); + System.out.println("Dropped table derbyDB"); + + /* + We release the result and statement resources. + */ + rs.close(); + s.close(); + System.out.println("Closed result set and statement"); + + /* + We end the transaction and the connection. + */ + conn.commit(); + conn.close(); + System.out.println("Committed transaction and closed connection"); + + /* + In embedded mode, an application should shut down Derby. + If the application fails to shut down Derby explicitly, + the Derby does not perform a checkpoint when the JVM shuts down, which means + that the next connection will be slower. + Explicitly shutting down Derby with the URL is preferred. + This style of shutdown will always throw an "exception". + */ + boolean gotSQLExc = false; + + if (framework.equals("embedded")) + { + try + { + DriverManager.getConnection("jdbc:derby:;shutdown=true"); + } + catch (SQLException se) + { + gotSQLExc = true; + } + + if (!gotSQLExc) + { + System.out.println("Database did not shut down normally"); + } + else + { + System.out.println("Database shut down normally"); + } + } + } + catch (Throwable e) + { + System.out.println("exception thrown:"); + + if (e instanceof SQLException) + { + printSQLError((SQLException) e); + } + else + { + e.printStackTrace(); + } + } + + System.out.println("SimpleApp finished"); + } + + static void printSQLError(SQLException e) + { + while (e != null) + { + System.out.println(e.toString()); + e = e.getNextException(); + } + } + + private void parseArguments(String[] args) + { + int length = args.length; + + for (int index = 0; index < length; index++) + { + if (args[index].equalsIgnoreCase("jccjdbcclient")) + { + framework = "jccjdbc"; + driver = "com.ibm.db2.jcc.DB2Driver"; + protocol = "jdbc:derby:net://localhost:1527/"; + } + } + } +} Propchange: incubator/derby/code/trunk/java/demo/simple/SimpleApp.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/derby/code/trunk/java/demo/simple/derby.properties URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/simple/derby.properties?rev=164630&r1=164629&r2=164630&view=diff ============================================================================== --- incubator/derby/code/trunk/java/demo/simple/derby.properties (original) +++ incubator/derby/code/trunk/java/demo/simple/derby.properties Mon Apr 25 12:29:37 2005 @@ -1,4 +1,4 @@ -# derby.properties -# -# we are using the default properties values for this demo -# +# derby.properties +# +# we are using the default properties values for this demo +# Propchange: incubator/derby/code/trunk/java/demo/simple/derby.properties ------------------------------------------------------------------------------ svn:eol-style = native Modified: incubator/derby/code/trunk/java/demo/simple/example.html URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/simple/example.html?rev=164630&r1=164629&r2=164630&view=diff ============================================================================== --- incubator/derby/code/trunk/java/demo/simple/example.html (original) +++ incubator/derby/code/trunk/java/demo/simple/example.html Mon Apr 25 12:29:37 2005 @@ -1,259 +1,259 @@ - - - - - - - - -Simple JDBC Application - - - - - - - - - - - - -

- Simple JDBC Application -

- - - -

Overview -

-

- This example program is a very minimal JDBC application. JDBC is the primary API for interacting with Apache Derby. This program accomplishes the following tasks: -

-

- The application runs in an embedded environment. This is the simplest Derby environment. The application starts up an instance of Derby within the current JVM and shuts down the instance before it completes. No network access is involved. In an embedded environment, only one application at a time can access a database. -

What's Included? -

-

- Before running this demo, you should see the following files and directories in the /demo/programs/simple directory: -

-

- After running the demo, you will see some new files and directories: -

-

How to Run This Sample Application in an Embedded Environment -

-
  1. Open a command window and change directories to the /demo/programs/simple directory. -
  2. If you haven't set it already on a system-wide basis, set the DERBY_INSTALL environment variable to the location of the directory where you installed the Derby software in the current command window. -
  3. In the command window, set CLASSPATH as follows:

    - - - - - - - - - - - - - -

    Library or Directory

    Path to Library or Directory

    main Derby library for the product:

    -

    derby.jar

    -

    %DERBY_INSTALL%/lib/derby.jar

    -

    current directory

    -

    .

    -
    - - -

    - - - - -

    -

    - - - -

    - A Note on Setting Class Path for an Embedded Environment -

    -

    Derby provides a script to help you get started setting class path in
    %DERBY_INSTALL%/frameworks/embedded/bin. This script is called setEmbeddedCP and comes in two flavors: one for Windows environment (this file ends with .bat) and one for UNIX environments (this file ends with .ksh). For users working in those environments, copying the commands in this file will help you get started setting the class path.

    -
    -

    - -

    -
  4. Run Derby's utility for testing the class path for an embedded environment. You will provide the arguments embedded to indicate an embedded environment and SimpleApp.class to test for the presence of the SimpleApp class. - - - -

    - You run the utility like this: -

    -

    java org.apache.derby.tools.sysinfo -cp arguments

    - - -

    - So for the arguments you need here, run it like this (all on one line): -

    -

    java org.apache.derby.tools.sysinfo -cp embedded SimpleApp.class

    - - -

    - If your environment is set up correctly, the utility shows output indicating success. It looks like this: -

    -

    FOUND IN CLASS PATH:

    -

    Derby embedded engine library (derby.jar)

    -

    -

    user-specified class (SimpleApp)

    -

    SUCCESS: All Derby-Related classes for embedded environment found in class path.

    - - - -

    - If something is missing from your class path environment, the utility indicates what is missing. For example, if you neglected to add the directory containing the SimpleApp class to your class path, the utility would indicate as such: -

    -

    Testing for presence of Derby-related libraries for embedded environment.

    -

    FOUND IN CLASS PATH:

    -

    -

    Derby embedded engine library (derby.jar)

    -

    -

    NOT FOUND IN CLASS PATH:

    -

    user-specified class (SimpleApp)

    -

    (SimpleApp not found.)

    -
  5. Once you have your environment set up correctly, execute the application from the same directory (/demo/programs/simple): -

    java SimpleApp

-

- A successful run produces the following output: -

SimpleApp starting in embedded mode. -
- Loaded the appropriate driver. -
- Connected to and created database derbyDB -
- Created table derbyDB -
- Inserted 1956 Webster -
- Inserted 1910 Union -
- Updated 1956 Webster to 180 Grand -
- Updated 180 Grand to 300 Lakeshore -
- Verified the rows -
- Dropped table derbyDB -
- Closed result set and statement -
- Committed transaction and closed connection -
- Database shut down normally -
- SimpleApp finished -
-

- - - - - + + + + + + + + +Simple JDBC Application + + + + + + + + + + + + +

+ Simple JDBC Application +

+ + + +

Overview +

+

+ This example program is a very minimal JDBC application. JDBC is the primary API for interacting with Apache Derby. This program accomplishes the following tasks: +

+

+ The application runs in an embedded environment. This is the simplest Derby environment. The application starts up an instance of Derby within the current JVM and shuts down the instance before it completes. No network access is involved. In an embedded environment, only one application at a time can access a database. +

What's Included? +

+

+ Before running this demo, you should see the following files and directories in the /demo/programs/simple directory: +

+

+ After running the demo, you will see some new files and directories: +

+

How to Run This Sample Application in an Embedded Environment +

+
  1. Open a command window and change directories to the /demo/programs/simple directory. +
  2. If you haven't set it already on a system-wide basis, set the DERBY_INSTALL environment variable to the location of the directory where you installed the Derby software in the current command window. +
  3. In the command window, set CLASSPATH as follows:

    + + + + + + + + + + + + + +

    Library or Directory

    Path to Library or Directory

    main Derby library for the product:

    +

    derby.jar

    +

    %DERBY_INSTALL%/lib/derby.jar

    +

    current directory

    +

    .

    +
    + + +

    + + + + +

    +

    + + + +

    + A Note on Setting Class Path for an Embedded Environment +

    +

    Derby provides a script to help you get started setting class path in
    %DERBY_INSTALL%/frameworks/embedded/bin. This script is called setEmbeddedCP and comes in two flavors: one for Windows environment (this file ends with .bat) and one for UNIX environments (this file ends with .ksh). For users working in those environments, copying the commands in this file will help you get started setting the class path.

    +
    +

    + +

    +
  4. Run Derby's utility for testing the class path for an embedded environment. You will provide the arguments embedded to indicate an embedded environment and SimpleApp.class to test for the presence of the SimpleApp class. + + + +

    + You run the utility like this: +

    +

    java org.apache.derby.tools.sysinfo -cp arguments

    + + +

    + So for the arguments you need here, run it like this (all on one line): +

    +

    java org.apache.derby.tools.sysinfo -cp embedded SimpleApp.class

    + + +

    + If your environment is set up correctly, the utility shows output indicating success. It looks like this: +

    +

    FOUND IN CLASS PATH:

    +

    Derby embedded engine library (derby.jar)

    +

    +

    user-specified class (SimpleApp)

    +

    SUCCESS: All Derby-Related classes for embedded environment found in class path.

    + + + +

    + If something is missing from your class path environment, the utility indicates what is missing. For example, if you neglected to add the directory containing the SimpleApp class to your class path, the utility would indicate as such: +

    +

    Testing for presence of Derby-related libraries for embedded environment.

    +

    FOUND IN CLASS PATH:

    +

    +

    Derby embedded engine library (derby.jar)

    +

    +

    NOT FOUND IN CLASS PATH:

    +

    user-specified class (SimpleApp)

    +

    (SimpleApp not found.)

    +
  5. Once you have your environment set up correctly, execute the application from the same directory (/demo/programs/simple): +

    java SimpleApp

+

+ A successful run produces the following output: +

SimpleApp starting in embedded mode. +
+ Loaded the appropriate driver. +
+ Connected to and created database derbyDB +
+ Created table derbyDB +
+ Inserted 1956 Webster +
+ Inserted 1910 Union +
+ Updated 1956 Webster to 180 Grand +
+ Updated 180 Grand to 300 Lakeshore +
+ Verified the rows +
+ Dropped table derbyDB +
+ Closed result set and statement +
+ Committed transaction and closed connection +
+ Database shut down normally +
+ SimpleApp finished +
+

+ + + + + Propchange: incubator/derby/code/trunk/java/demo/simple/example.html ------------------------------------------------------------------------------ svn:eol-style = native