Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 6575 invoked from network); 25 Apr 2005 19:29:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 25 Apr 2005 19:29:47 -0000 Received: (qmail 92631 invoked by uid 500); 25 Apr 2005 19:30:19 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 92589 invoked by uid 500); 25 Apr 2005 19:30:18 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 92560 invoked by uid 500); 25 Apr 2005 19:30:18 -0000 Delivered-To: apmail-incubator-derby-cvs@incubator.apache.org Received: (qmail 92537 invoked by uid 99); 25 Apr 2005 19:30:17 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Mon, 25 Apr 2005 12:30:15 -0700 Received: (qmail 6500 invoked by uid 65534); 25 Apr 2005 19:29:41 -0000 Message-ID: <20050425192941.6494.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r164630 [3/3] - in /incubator/derby/code/trunk/java/demo: ./ nserverdemo/ simple/ Date: Mon, 25 Apr 2005 19:29:38 -0000 To: derby-cvs@incubator.apache.org From: fuzzylogic@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/derby/code/trunk/java/demo/nserverdemo/readme.html URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/nse= rverdemo/readme.html?rev=3D164630&r1=3D164629&r2=3D164630&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 connec= tions 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 netwo= rk 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 pre= fix is jdbc:derby:net:

-
    - -
  • First scenario: Simple Network Server Sample

    -

    This example uses two programs to illustrate ho= w 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 (SimpleN= etworkClientSample) and the server program (SimpleNetworkServerSample) each= run in their own (different) JVMs. The example shows the Derby jar files t= hat are needed at the client side and server side to use the Network Server= . The SimpleNetworkClientSample program also shows how to use the DriverMan= ger or a DataSource to obtain client connections.

  • - -
  • Second scenario: Network Server Demo

    -

    This example program (NsSample) starts the netw= ork server and shows how to obtain client and embedded connections using th= e Network Server to connect to the same database, all in one JVM.

  • <= /LI> - -
- - - + + + +Example Programs + + + + +

Overview

+

The following example scenarios show you how to obtain an embedded connection and client connec= tions 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 netwo= rk 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 pre= fix is jdbc:derby:net:

+
    + +
  • First scenario: Simple Network Server Sample

    +

    This example uses two programs to illustrate ho= w 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 (SimpleN= etworkClientSample) and the server program (SimpleNetworkServerSample) each= run in their own (different) JVMs. The example shows the Derby jar files t= hat are needed at the client side and server side to use the Network Server= . The SimpleNetworkClientSample program also shows how to use the DriverMan= ger or a DataSource to obtain client connections.

  • + +
  • Second scenario: Network Server Demo

    +

    This example program (NsSample) starts the netw= ork server and shows how to obtain client and embedded connections using th= e Network Server to connect to the same database, all in one JVM.

  • <= /LI> + +
+ + + Propchange: incubator/derby/code/trunk/java/demo/nserverdemo/readme.html ---------------------------------------------------------------------------= --- svn:eol-style =3D native Modified: incubator/derby/code/trunk/java/demo/nserverdemo/simpleserversamp= le.html URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/nse= rverdemo/simpleserversample.html?rev=3D164630&r1=3D164629&r2=3D164630&view= =3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/demo/nserverdemo/simpleserversample.htm= l (original) +++ incubator/derby/code/trunk/java/demo/nserverdemo/simpleserversample.htm= l 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 ac= cess -it at a time. The embedded driver is loaded when the Network Server is sta= rted. -Hence, the JVM that starts the Network Server can get an embedded connecti= on to -the same database that Network Server is accessing to serve the clients fr= om -other JVMs. This solution allows you to take advantage of the performance -benefits of the embedded driver as well as allow for client connections fr= om other -JVMs to connect to the same database.

- -

In this example, the following two programs show how to setup the serve= r 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:

- -
    -
  • starts the Derby Network Server using a property and also loads the e= mbedded driver
  • -
  • checks if the Derby Network Server is up and running
  • -
  • creates the database 'NSSimpleDB' if not already created
  • -
  • obtains an embedded database connection
  • -
  • tests the database connection by executing a sample query
  • -
  • allows for client connections to connect to the server until the user= decides to stop the server and exit the program
  • -
  • closes the connection
  • -
  • shuts down the Derby - Network Server before exiting the program.
  • -
- -

The following files should be installed in the %DE= RBY_INSTALL%\demo\programs\nserverdemo\ direct= ory in -order to run this sample program:

- -
    -
  • Source file:
  • -
      -
    • SimpleNetworkServerSample.java
    • -
    -
  • Compiled class file:
  • -
      -
    • SimpleNetworkServerSample.class
    • -
    -
- -

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 d= irectory - where you installed Derby.
  2. -
  3. Set the CLASSPATH to include the following jar files in order to run = this - program.
  4. -
    • the current directory (".")
    • -
    • derbynet.jar:
      The Network Server jar file. It must be in = your CLASSPATH since we start the Network Server in this program.
    • -
    • derby.jar:
      The Derby database engine jar file.
    • -
    - -
  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. <= /p>

  6. - -
  7. Once you have set up your environment correctly, execute the applicati= on from the
    %DERBY_INSTALL%\demo\programs\n= serverdemo 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.<= /span>
Testing embedded connection by executing a sample query
= number of rows in sys.systables =3D 16

While my = app is busy with embedded work, ij might connect like this:
$ java -Dij.user=3Dme -= Dij.password=3Dpw -Dij.protocol=3Djdbc:der= by:net://localhost:1527/ org.apache.derby.tools.ij
= ij> connect 'NSSimpleDB:retri= eveMessagesFromServerOnGetMessage=3Dtrue;';
Watch that punctuatio= n=2E Put a ':' before the jcc
attributes and = a ';' after each one (even the last).


Clients can continue to co= nnect:
Press [Enter] to stop Server
- -

Running this program will also create new directories and files:

- -
    -
  • NSSimpleDB
    -This directory makes up the NSSimpleDB database. -
  • -
  • derby.log
    -This log file contains Derby progress and error messages. -
- - -

Example of a Client connecting to the Network Server

- -

SimpleNetworkClientSample program

- -

This program:

- -
    -
  • loads the DB2 JDBC Universal Driver
  • -
  • obtains a client connection using the Driver Manager
  • -
  • obtains a client connection using a DataSource
  • -
  • tests the database connections by executing a sample query
  • -
  • closes the connections and then exits the program.
  • -
- -

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

-
    -
  • Source file:
    SimpleNetworkClientSample.java
  • -
  • Compiled class file:
    SimpleNetworkClientSample.class -
- -

How to run the SimpleNetworkClientSample program

- -

To connect to the Network Server that has been started as part of the S= impleNetworkServerSample program:

- -
    -
  1. Open a command prompt and change directories to the %DERBY_INSTALL%\demo\programs\nserverdemo directory, wh= ere %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: -
      -
    • the current directory (".")
    • -
    • db2jcc.jar
      This jar file must be in your CLASSPATH to us= e the DB2 JDBC Universal Driver.
    • -
    • db2jcc_license_c.jar
      This jar file is the license file f= or the Universal Driver for Derby.
    • -
  4. -
  5. Once you have set up your environment correctly, execute the -application from the
    %DERBY_INSTALL%\d= emo\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 th= e DriverManager.
connection from = datasource; getDriverName =3D IBM DB2 JDBC Universal Dr= iver Architecture
Got a client connection via a DataSource.
Testing the connection obtained via DriverManager by executing a sample query
number of rows in sy= s=2Esystables =3D 16
Testing the connection obtained via a = DataSource by executing a sample query
number of row= s in sys.systables =3D 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 ac= cess +it at a time. The embedded driver is loaded when the Network Server is sta= rted. +Hence, the JVM that starts the Network Server can get an embedded connecti= on to +the same database that Network Server is accessing to serve the clients fr= om +other JVMs. This solution allows you to take advantage of the performance +benefits of the embedded driver as well as allow for client connections fr= om other +JVMs to connect to the same database.

+ +

In this example, the following two programs show how to setup the serve= r 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:

+ +
    +
  • starts the Derby Network Server using a property and also loads the e= mbedded driver
  • +
  • checks if the Derby Network Server is up and running
  • +
  • creates the database 'NSSimpleDB' if not already created
  • +
  • obtains an embedded database connection
  • +
  • tests the database connection by executing a sample query
  • +
  • allows for client connections to connect to the server until the user= decides to stop the server and exit the program
  • +
  • closes the connection
  • +
  • shuts down the Derby + Network Server before exiting the program.
  • +
+ +

The following files should be installed in the %DE= RBY_INSTALL%\demo\programs\nserverdemo\ direct= ory in +order to run this sample program:

+ +
    +
  • Source file:
  • +
      +
    • SimpleNetworkServerSample.java
    • +
    +
  • Compiled class file:
  • +
      +
    • SimpleNetworkServerSample.class
    • +
    +
+ +

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 d= irectory + where you installed Derby.
  2. +
  3. Set the CLASSPATH to include the following jar files in order to run = this + program.
  4. +
    • the current directory (".")
    • +
    • derbynet.jar:
      The Network Server jar file. It must be in = your CLASSPATH since we start the Network Server in this program.
    • +
    • derby.jar:
      The Derby database engine jar file.
    • +
    + +
  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. <= /p>

  6. + +
  7. Once you have set up your environment correctly, execute the applicati= on from the
    %DERBY_INSTALL%\demo\programs\n= serverdemo 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.<= /span>
Testing embedded connection by executing a sample query
= number of rows in sys.systables =3D 16

While my = app is busy with embedded work, ij might connect like this:
$ java -Dij.user=3Dme -= Dij.password=3Dpw -Dij.protocol=3Djdbc:der= by:net://localhost:1527/ org.apache.derby.tools.ij
= ij> connect 'NSSimpleDB:retri= eveMessagesFromServerOnGetMessage=3Dtrue;';
Watch that punctuatio= n=2E Put a ':' before the jcc
attributes and = a ';' after each one (even the last).


Clients can continue to co= nnect:
Press [Enter] to stop Server
+ +

Running this program will also create new directories and files:

+ +
    +
  • NSSimpleDB
    +This directory makes up the NSSimpleDB database. +
  • +
  • derby.log
    +This log file contains Derby progress and error messages. +
+ + +

Example of a Client connecting to the Network Server

+ +

SimpleNetworkClientSample program

+ +

This program:

+ +
    +
  • loads the DB2 JDBC Universal Driver
  • +
  • obtains a client connection using the Driver Manager
  • +
  • obtains a client connection using a DataSource
  • +
  • tests the database connections by executing a sample query
  • +
  • closes the connections and then exits the program.
  • +
+ +

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

+
    +
  • Source file:
    SimpleNetworkClientSample.java
  • +
  • Compiled class file:
    SimpleNetworkClientSample.class
  • +
+ +

How to run the SimpleNetworkClientSample program

+ +

To connect to the Network Server that has been started as part of the S= impleNetworkServerSample program:

+ +
    +
  1. Open a command prompt and change directories to the %DERBY_INSTALL%\demo\programs\nserverdemo directory, wh= ere %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: +
      +
    • the current directory (".")
    • +
    • db2jcc.jar
      This jar file must be in your CLASSPATH to us= e the DB2 JDBC Universal Driver.
    • +
    • db2jcc_license_c.jar
      This jar file is the license file f= or the Universal Driver for Derby.
    • +
  4. +
  5. Once you have set up your environment correctly, execute the +application from the
    %DERBY_INSTALL%\d= emo\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 th= e DriverManager.
connection from = datasource; getDriverName =3D IBM DB2 JDBC Universal Dr= iver Architecture
Got a client connection via a DataSource.
Testing the connection obtained via DriverManager by executing a sample query
number of rows in sy= s=2Esystables =3D 16
Testing the connection obtained via a = DataSource by executing a sample query
number of row= s in sys.systables =3D 16
Goodbye!
+ + + + Propchange: incubator/derby/code/trunk/java/demo/nserverdemo/simpleserversa= mple.html ---------------------------------------------------------------------------= --- svn:eol-style =3D native Modified: incubator/derby/code/trunk/java/demo/readme.html URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/rea= dme.html?rev=3D164630&r1=3D164629&r2=3D164630&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/demo/readme.html (original) +++ incubator/derby/code/trunk/java/demo/readme.html Mon Apr 25 12:29:37 20= 05 @@ -1,15 +1,15 @@ - - - - - - - =20 - - - - - - - - + + + + + + + =20 + + + + + + + + Propchange: incubator/derby/code/trunk/java/demo/readme.html ---------------------------------------------------------------------------= --- svn:eol-style =3D native Modified: incubator/derby/code/trunk/java/demo/simple/SimpleApp.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/sim= ple/SimpleApp.java?rev=3D164630&r1=3D164629&r2=3D164630&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/demo/simple/SimpleApp.java (original) +++ incubator/derby/code/trunk/java/demo/simple/SimpleApp.java Mon Apr 25 1= 2:29:37 2005 @@ -1,244 +1,244 @@ -/* - - Derby - Class SimpleApp - - Copyright 2001, 2004 The Apache Software Foundation or its licensors, a= s 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 framewor= k, - * the application runs in a different JVM from Derby. The application onl= y needs - * to start the client driver, and the connectivity framework provides net= work 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 fram= ework) - * - * @author janet - */ -public class SimpleApp -{ - /* the default framework is embedded*/ - public String framework =3D "embedded"; - public String driver =3D "org.apache.derby.jdbc.EmbeddedDriver"; - public String protocol =3D "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 =3D null; - Properties props =3D new Properties(); - props.put("user", "user1"); - props.put("password", "user1"); - - /* - The connection specifies create=3Dtrue 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 =3D DriverManager.getConnection(protocol + - "derbyDB;create=3Dtrue", 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 =3D 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=3D180, addr=3D'Grand Ave.' where n= um=3D1956"); - System.out.println("Updated 1956 Webster to 180 Grand"); - - s.execute( - "update derbyDB set num=3D300, addr=3D'Lakeshore Ave.' whe= re num=3D180"); - System.out.println("Updated 180 Grand to 300 Lakeshore"); - - /* - We select the rows and verify the results. - */ - ResultSet rs =3D s.executeQuery( - "SELECT num, addr FROM derbyDB ORDER BY num"); - - if (!rs.next()) - { - throw new Exception("Wrong number of rows"); - } - - if (rs.getInt(1) !=3D 300) - { - throw new Exception("Wrong row returned"); - } - - if (!rs.next()) - { - throw new Exception("Wrong number of rows"); - } - - if (rs.getInt(1) !=3D 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 connectio= n"); - - /* - 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 =3D false; - - if (framework.equals("embedded")) - { - try - { - DriverManager.getConnection("jdbc:derby:;shutdown=3Dtr= ue"); - } - catch (SQLException se) - { - gotSQLExc =3D true; - } - - if (!gotSQLExc) - { - System.out.println("Database did not shut down normall= y"); - } - 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 !=3D null) - { - System.out.println(e.toString()); - e =3D e.getNextException(); - } - } - - private void parseArguments(String[] args) - { - int length =3D args.length; - - for (int index =3D 0; index < length; index++) - { - if (args[index].equalsIgnoreCase("jccjdbcclient")) - { - framework =3D "jccjdbc"; - driver =3D "com.ibm.db2.jcc.DB2Driver"; - protocol =3D "jdbc:derby:net://localhost:1527/"; - } - } - } -} +/* + + Derby - Class SimpleApp + + Copyright 2001, 2004 The Apache Software Foundation or its licensors, a= s 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 framewor= k, + * the application runs in a different JVM from Derby. The application onl= y needs + * to start the client driver, and the connectivity framework provides net= work 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 fram= ework) + * + * @author janet + */ +public class SimpleApp +{ + /* the default framework is embedded*/ + public String framework =3D "embedded"; + public String driver =3D "org.apache.derby.jdbc.EmbeddedDriver"; + public String protocol =3D "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 =3D null; + Properties props =3D new Properties(); + props.put("user", "user1"); + props.put("password", "user1"); + + /* + The connection specifies create=3Dtrue 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 =3D DriverManager.getConnection(protocol + + "derbyDB;create=3Dtrue", 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 =3D 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=3D180, addr=3D'Grand Ave.' where n= um=3D1956"); + System.out.println("Updated 1956 Webster to 180 Grand"); + + s.execute( + "update derbyDB set num=3D300, addr=3D'Lakeshore Ave.' whe= re num=3D180"); + System.out.println("Updated 180 Grand to 300 Lakeshore"); + + /* + We select the rows and verify the results. + */ + ResultSet rs =3D s.executeQuery( + "SELECT num, addr FROM derbyDB ORDER BY num"); + + if (!rs.next()) + { + throw new Exception("Wrong number of rows"); + } + + if (rs.getInt(1) !=3D 300) + { + throw new Exception("Wrong row returned"); + } + + if (!rs.next()) + { + throw new Exception("Wrong number of rows"); + } + + if (rs.getInt(1) !=3D 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 connectio= n"); + + /* + 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 =3D false; + + if (framework.equals("embedded")) + { + try + { + DriverManager.getConnection("jdbc:derby:;shutdown=3Dtr= ue"); + } + catch (SQLException se) + { + gotSQLExc =3D true; + } + + if (!gotSQLExc) + { + System.out.println("Database did not shut down normall= y"); + } + 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 !=3D null) + { + System.out.println(e.toString()); + e =3D e.getNextException(); + } + } + + private void parseArguments(String[] args) + { + int length =3D args.length; + + for (int index =3D 0; index < length; index++) + { + if (args[index].equalsIgnoreCase("jccjdbcclient")) + { + framework =3D "jccjdbc"; + driver =3D "com.ibm.db2.jcc.DB2Driver"; + protocol =3D "jdbc:derby:net://localhost:1527/"; + } + } + } +} Propchange: incubator/derby/code/trunk/java/demo/simple/SimpleApp.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Modified: incubator/derby/code/trunk/java/demo/simple/derby.properties URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/sim= ple/derby.properties?rev=3D164630&r1=3D164629&r2=3D164630&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 =3D native Modified: incubator/derby/code/trunk/java/demo/simple/example.html URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/demo/sim= ple/example.html?rev=3D164630&r1=3D164629&r2=3D164630&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 -

-=20 - - -

Overview -

-

- This example program is a very minimal JDBC appl= ication. JDBC is the primary API for interacting with Apache Derby. This pr= ogram accomplishes the following tasks: -

  • st= arts up the Derby engine, if necessary -
  • creates and connects to a d= atabase -
  • creates a table -
  • inserts data -
  • updates data -
  • selects data -
  • drops a table -
  • disconnects -
  • shuts down Derby, if necess= ary -
-

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

What's Included? -

-

- Before running this demo, you should see the fol= lowing files and directories in the /demo/programs/s= imple directory: -

  • example.html - -=20 - -

    - This file. -

    -
  • -SimpleApp.java - -=20 - -

    - 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 applic= ation behaves in the various environments. -

    -
  • -derby.properties - -=20 - -

    - Properties file for the Derby system. -

    -
  • Simp= leApp.class - -=20 - -

    - The compiled class file. -

    -
-

- After running the demo, you will see some new fi= les and directories: -

  • derbyDB (directory) - -=20 - -

    - The directory that makes up the derbyDB database. You must not modify anything in this director= y, or you will corrupt the database. The directory was created when the app= lication connected with Derby, using the attribute c= reate=3Dtrue in the database connection URL. The database name, derbyDB, was also set in the database connection URL.= =20 -

    -
  • derb= yDB\log (directory) - -=20 - -

    - The directory that holds the database log for th= e derbyDB database.=20 -

    -
  • derb= yDB\seg0 (directory) - -=20 - -

    - The directory that holds the data for the derbyDB database. -

    -
  • derb= yDB\service.properties - -=20 - -

    - An internal file that holds boot-time configurat= ion parameters for the derbyDB database; do not= edit. -

    -
  • derb= y=2ELOG - -=20 - -

    - The log file with Derby progress and error messa= ges. -

    -
-

How to Run This Sample Appl= ication 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 va= riable to the location of the directory where you installed the Derby softw= are in the current command window. -
  3. In the command = window, set CLASSPATH as follows:

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

    Library or Direct= ory

    Path to Library o= r Directory

    main Derby library for the product:

    -

    derby= .jar

    -

    %DERBY_INSTALL%/lib/derby.jar

    -

    current directory

    -

    .

    -
    - - -

    - - -=20 - -

    -

    - - - -

    - A Note on Setting Class Path for an Embedded Env= ironment -

    -

    Derby provides a script to h= elp you get started setting class path in
    %DERB= Y_INSTALL%/frameworks/embedded/bin. This script is called setEmbeddedCP and comes in two flavors: one for Windows env= ironment (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 uti= lity for testing the class path for an embedded environment. You will provi= de the arguments embedded to indicate an embedd= ed environment and SimpleApp.class to test for = the presence of the SimpleApp class. - -=20 - -

    - You run the utility like this: -

    -

    java org.apache.derby.tools.sy= sinfo -cp arguments

    -=20 - -

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

    -

    java org.apache.derby.tools.sy= sinfo -cp embedded SimpleApp.class

    -=20 - -

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

    -

    FOUND IN CLASS PATH: -

    Derby embedded engin= e library (derby.jar)

    -

    -

    user-specified clas= s (SimpleApp)

    -

    SUCCESS: All Derby-Rel= ated classes for embedded environment found in class path.

    - -=20 - -

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

    -

    Testing for presence o= f Derby-related libraries for embedded environment.

    -

    FOUND IN CLASS PATH: -

    -

    Derby embedded engi= ne library (derby.jar)

    -

    -

    NOT FOUND IN CLASS PAT= H:

    -

    user-specified clas= s (SimpleApp)

    -

    (SimpleApp not fou= nd.)

    -
  5. Once you have y= our environment set up correctly, execute the application from the same dir= ectory (/demo/programs/simple):=20 -

    java SimpleApp

-

- A successful run produces the following output:=20 -

SimpleApp starting in embe= dded 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

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

+ Simple JDBC Application +

+=20 + + +

Overview +

+

+ This example program is a very minimal JDBC appl= ication. JDBC is the primary API for interacting with Apache Derby. This pr= ogram accomplishes the following tasks: +

  • st= arts up the Derby engine, if necessary +
  • creates and connects to a d= atabase +
  • creates a table +
  • inserts data +
  • updates data +
  • selects data +
  • drops a table +
  • disconnects +
  • shuts down Derby, if necess= ary +
+

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

What's Included? +

+

+ Before running this demo, you should see the fol= lowing files and directories in the /demo/programs/s= imple directory: +

  • example.html + +=20 + +

    + This file. +

    +
  • +SimpleApp.java + +=20 + +

    + 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 applic= ation behaves in the various environments. +

    +
  • +derby.properties + +=20 + +

    + Properties file for the Derby system. +

    +
  • Simp= leApp.class + +=20 + +

    + The compiled class file. +

    +
+

+ After running the demo, you will see some new fi= les and directories: +

  • derbyDB (directory) + +=20 + +

    + The directory that makes up the derbyDB database. You must not modify anything in this director= y, or you will corrupt the database. The directory was created when the app= lication connected with Derby, using the attribute c= reate=3Dtrue in the database connection URL. The database name, derbyDB, was also set in the database connection URL.=20 +

    +
  • derb= yDB\log (directory) + +=20 + +

    + The directory that holds the database log for th= e derbyDB database.=20 +

    +
  • derb= yDB\seg0 (directory) + +=20 + +

    + The directory that holds the data for the derbyDB database. +

    +
  • derb= yDB\service.properties + +=20 + +

    + An internal file that holds boot-time configurat= ion parameters for the derbyDB database; do not= edit. +

    +
  • derb= y=2ELOG + +=20 + +

    + The log file with Derby progress and error messa= ges. +

    +
+

How to Run This Sample Appl= ication 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 va= riable to the location of the directory where you installed the Derby softw= are in the current command window. +
  3. In the command = window, set CLASSPATH as follows:

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

    Library or Direct= ory

    Path to Library o= r Directory

    main Derby library for the product:

    +

    derby= .jar

    +

    %DERBY_INSTALL%/lib/derby.jar

    +

    current directory

    +

    .

    +
    + + +

    + + +=20 + +

    +

    + + + +

    + A Note on Setting Class Path for an Embedded Env= ironment +

    +

    Derby provides a script to h= elp you get started setting class path in
    %DERB= Y_INSTALL%/frameworks/embedded/bin. This script is called setEmbeddedCP and comes in two flavors: one for Windows env= ironment (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 uti= lity for testing the class path for an embedded environment. You will provi= de the arguments embedded to indicate an embedd= ed environment and SimpleApp.class to test for = the presence of the SimpleApp class. + +=20 + +

    + You run the utility like this: +

    +

    java org.apache.derby.tools.sy= sinfo -cp arguments

    +=20 + +

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

    +

    java org.apache.derby.tools.sy= sinfo -cp embedded SimpleApp.class

    +=20 + +

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

    +

    FOUND IN CLASS PATH: +

    Derby embedded engin= e library (derby.jar)

    +

    +

    user-specified clas= s (SimpleApp)

    +

    SUCCESS: All Derby-Rel= ated classes for embedded environment found in class path.

    + +=20 + +

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

    +

    Testing for presence o= f Derby-related libraries for embedded environment.

    +

    FOUND IN CLASS PATH: +

    +

    Derby embedded engi= ne library (derby.jar)

    +

    +

    NOT FOUND IN CLASS PAT= H:

    +

    user-specified clas= s (SimpleApp)

    +

    (SimpleApp not fou= nd.)

    +
  5. Once you have y= our environment set up correctly, execute the application from the same dir= ectory (/demo/programs/simple):=20 +

    java SimpleApp

+

+ A successful run produces the following output:=20 +

SimpleApp starting in embe= dded 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 =3D native