Return-Path:
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. 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. 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. In particular, this program: The following files should be installed in the %DE=
RBY_INSTALL%\demo\programs\nserverdemo\ direct=
ory in
-order to run this sample program: To run this simple Derby Network Server sample program: This command will show the Derby jar files that are in the CLASSPATH. <=
/p> You should receive output similar to the following if the program runs =
successfully: Running this program will also create new directories and files: This program: The following files should be installed in the %DE=
RBY_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 S=
impleNetworkServerSample program: You should receive output similar to the following if the program runs
-successfully: 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. In particular, this program: The following files should be installed in the %DE=
RBY_INSTALL%\demo\programs\nserverdemo\ direct=
ory in
+order to run this sample program: To run this simple Derby Network Server sample program: This command will show the Derby jar files that are in the CLASSPATH. <=
/p> You should receive output similar to the following if the program runs =
successfully: Running this program will also create new directories and files: This program: The following files should be installed in the %DE=
RBY_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 S=
impleNetworkServerSample program: You should receive output similar to the following if the program runs
+successfully: 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 @@
-
-
-
- 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:
-
- 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.
-
- Before running this demo, you should see the fol=
lowing files and directories in the /demo/programs/s=
imple 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 applic=
ation behaves in the various environments.
-
- After running the demo, you will see some new fi=
les and directories:
-
- 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
-
- The directory that holds the database log for th=
e derbyDB database.=20
-
- The directory that holds the data for the derbyDB database.
-
- An internal file that holds boot-time configurat=
ion parameters for the derbyDB database; do not=
edit.
- 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 .Overview
-
-
-
-
-
-
+
+
+
+Overview
+
+
+
+
+
+
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 @@
-
-
-
-
-
-Simple Derby Network Server Example
-
-Overview
-
-SimpleNetworkServerSample program
-
-
-
-
-
-
-
-
-
-
-
-How to run the SimpleNetworkServerSample program
-
-
-
-
-
-
The Network Server jar file. It must be in =
your CLASSPATH since we start the Network Server in this program.
The Derby database engine jar file.java org.apache.derby.tools.sysinfo
-
-
%DERBY_INSTALL%\demo\programs\n=
serverdemo directory:
-
-java SimpleNetworkServerSample
-
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
-
-
-
-
-
-
-This directory makes up the NSSimpleDB database.
-
-This log file contains Derby progress and error messages.
-Example of a Client connecting to the Network Server
-
-SimpleNetworkClientSample program
-
-
-
-
-
-
-
-
SimpleNetworkClientSample.java
SimpleNetworkClientSample.classHow to run the SimpleNetworkClientSample program
-
-
-
-
-
-
This jar file must be in your CLASSPATH to us=
e the DB2 JDBC Universal Driver.
This jar file is the license file f=
or the Universal Driver for Derby.
%DERBY_INSTALL%\d=
emo\programs\nserverdemo\ directory:
-java SimpleNetworkClientSample
-
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=
span>.
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!
-
-
-
-
+
+
+
+
+
+Simple Derby Network Server Example
+
+Overview
+
+SimpleNetworkServerSample program
+
+
+
+
+
+
+
+
+
+
+
+How to run the SimpleNetworkServerSample program
+
+
+
+
+
+
The Network Server jar file. It must be in =
your CLASSPATH since we start the Network Server in this program.
The Derby database engine jar file.java org.apache.derby.tools.sysinfo
+
+
%DERBY_INSTALL%\demo\programs\n=
serverdemo directory:
+
+java SimpleNetworkServerSample
+
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
+
+
+
+
+
+
+This directory makes up the NSSimpleDB database.
+
+This log file contains Derby progress and error messages.
+Example of a Client connecting to the Network Server
+
+SimpleNetworkClientSample program
+
+
+
+
+
+
+
+
SimpleNetworkClientSample.java
SimpleNetworkClientSample.classHow to run the SimpleNetworkClientSample program
+
+
+
+
+
+
This jar file must be in your CLASSPATH to us=
e the DB2 JDBC Universal Driver.
This jar file is the license file f=
or the Universal Driver for Derby.
%DERBY_INSTALL%\d=
emo\programs\nserverdemo\ directory:
+java SimpleNetworkClientSample
+
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=
span>.
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 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
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.)
- *
- *
- Simple JDBC Application
-
-=20
-
-
- Overview
-
-
- What's Included?
-
-
-
- How to Run This Sample Appl=
ication in an Embedded Environment
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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: -
-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.
- -Derby embedded engi= ne library (derby.jar)
- - - - -- 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
- - - + + + + + + + + ++ 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: +
+ 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. +
+ Before running this demo, you should see the fol= lowing files and directories in the /demo/programs/s= imple 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 applic= ation behaves in the various environments. +
++ After running the demo, you will see some new fi= les and directories: +
+ 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 +
++ The directory that holds the database log for th= e derbyDB database.=20 +
++ The directory that holds the data for the derbyDB database. +
++ An internal file that holds boot-time configurat= ion parameters for the derbyDB database; do not= edit. +
+ 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 + |
+ . + |
+
+ 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: +
+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.
+ +Derby embedded engi= ne library (derby.jar)
+ + + + ++ 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