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 @@ - - -
-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:
-First scenario: Simple Network Server Sample
-This example uses two programs to illustrate how a typical client program that starts up in its own JVM can connect to the Network Server that the server program starts. The client program (SimpleNetworkClientSample) and the server program (SimpleNetworkServerSample) each run in their own (different) JVMs. The example shows the Derby jar files that are needed at the client side and server side to use the Network Server. The SimpleNetworkClientSample program also shows how to use the DriverManger or a DataSource to obtain client connections.
Second scenario: Network Server Demo
-This example program (NsSample) starts the network server and shows how to obtain client and embedded connections using the Network Server to connect to the same database, all in one JVM.
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:
+First scenario: Simple Network Server Sample
+This example uses two programs to illustrate how a typical client program that starts up in its own JVM can connect to the Network Server that the server program starts. The client program (SimpleNetworkClientSample) and the server program (SimpleNetworkServerSample) each run in their own (different) JVMs. The example shows the Derby jar files that are needed at the client side and server side to use the Network Server. The SimpleNetworkClientSample program also shows how to use the DriverManger or a DataSource to obtain client connections.
Second scenario: Network Server Demo
+This example program (NsSample) starts the network server and shows how to obtain client and embedded connections using the Network Server to connect to the same database, all in one JVM.
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.
- -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:
- -To run this simple Derby Network Server sample program:
- -java org.apache.derby.tools.sysinfo- -
This command will show the Derby jar files that are in the CLASSPATH.
java SimpleNetworkServerSample-
You should receive output similar to the following if the program runs successfully:
-Starting Network ServerRunning this program will also create new directories and files:
- -This program:
- -The following files should be installed in the %DERBY_INSTALL%\demo\programs\nserverdemo\ directory in order to run this sample program:
-To connect to the Network Server that has been started as part of the SimpleNetworkServerSample program:
- -java SimpleNetworkClientSample-
You should receive output similar to the following if the program runs -successfully:
- -Starting Sample client programThe 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.
+ +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:
+ +To run this simple Derby Network Server sample program:
+ +java org.apache.derby.tools.sysinfo+ +
This command will show the Derby jar files that are in the CLASSPATH.
java SimpleNetworkServerSample+
You should receive output similar to the following if the program runs successfully:
+Starting Network ServerRunning this program will also create new directories and files:
+ +This program:
+ +The following files should be installed in the %DERBY_INSTALL%\demo\programs\nserverdemo\ directory in order to run this sample program:
+To connect to the Network Server that has been started as part of the SimpleNetworkServerSample program:
+ +java SimpleNetworkClientSample+
You should receive output similar to the following if the program runs +successfully:
+ +Starting Sample client programWhen 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 @@ - - -
- - - - - -- 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. -
- Before running this demo, you should see the following files and directories in the /demo/programs/simple directory: -
- Source code for the example program that starts up Derby, creates a database, does some inserts and updates, and then shuts down Derby. Examine this file to see how the application behaves in the various environments. -
-- After running the demo, you will see some new files and directories: -
- The directory that makes up the derbyDB database. You must not modify anything in this directory, or you will corrupt the database. The directory was created when the application connected with Derby, using the attribute create=true in the database connection URL. The database name, derbyDB, was also set in the database connection URL. -
-- The directory that holds the database log for the derbyDB database. -
-- The directory that holds the data for the derbyDB database. -
-- An internal file that holds boot-time configuration parameters for the derbyDB database; do not edit. -
-| Library or Directory |
- Path to Library or Directory |
-
|---|---|
| main Derby library for the product: -derby.jar - |
- %DERBY_INSTALL%/lib/derby.jar - |
-
| current directory - |
- . - |
-
- 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: -
- -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.
- - -Derby embedded engine library (derby.jar)
- - - - -- 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
-
-
Apache Derby Version 10
- - - + + + + + + + + ++ 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. +
+ Before running this demo, you should see the following files and directories in the /demo/programs/simple directory: +
+ Source code for the example program that starts up Derby, creates a database, does some inserts and updates, and then shuts down Derby. Examine this file to see how the application behaves in the various environments. +
++ After running the demo, you will see some new files and directories: +
+ The directory that makes up the derbyDB database. You must not modify anything in this directory, or you will corrupt the database. The directory was created when the application connected with Derby, using the attribute create=true in the database connection URL. The database name, derbyDB, was also set in the database connection URL. +
++ The directory that holds the database log for the derbyDB database. +
++ The directory that holds the data for the derbyDB database. +
++ An internal file that holds boot-time configuration parameters for the derbyDB database; do not edit. +
+| Library or Directory |
+ Path to Library or Directory |
+
|---|---|
| main Derby library for the product: +derby.jar + |
+ %DERBY_INSTALL%/lib/derby.jar + |
+
| current directory + |
+ . + |
+
+ 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: +
+ +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.
+ + +Derby embedded engine library (derby.jar)
+ + + + ++ 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
+
+
Apache Derby Version 10
+ + + Propchange: incubator/derby/code/trunk/java/demo/simple/example.html ------------------------------------------------------------------------------ svn:eol-style = native