Simple JDBC Application

Overview

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

This Example and Cloudscape Environments

The application can run in any of the following environments:

This example shows that the application works almost the same regardless of the environment. Only minor modifications to the code are needed to suit the environment.

What's Included?

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

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

How to Run This Sample Application

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 CLOUDSCAPE_INSTALL environment variable to the location of the directory you installed the Cloudscape software in the current command window.
  3. In the command window, set CLASSPATH as follows:

    Library or Directory

    Path to Library or Directory

    main Cloudscape library for your product

    (cloudscape.jar or
    cloudsync.jar)

    %CLOUDSCAPE_INSTALL%/lib/NameOfYourLibrary

    current directory

    .

    A Note on Setting Class Path for an Embedded Environment

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

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

    You run the utility like this:

    java COM.cloudscape.tools.sysinfo -cp arguments

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

    java COM.cloudscape.tools.sysinfo -cp embedded CloudscapeSimpleApp.class

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

    FOUND IN CLASS PATH:

    Cloudscape primary library (cloudscape.jar or cloudsync.jar)

    Valid Cloudscape license

    user-specified class (CloudscapeSimpleApp)

    SUCCESS: All Cloudscape-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 CloudscapeSimpleApp class to your class path, the utility would indicate as such:

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

    FOUND IN CLASS PATH:

    Cloudscape primary library (cloudscape.jar or cloudsync.jar)

    Valid Cloudscape license

    NOT FOUND IN CLASS PATH:

    user-specified class (CloudscapeSimpleApp)

    (CloudscapeSimpleApp not found.)

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

    java CloudscapeSimpleApp

A successful run produces the following output:

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

Client/Server Environment

Cloudconnector

In this demo, you start Cloudconnector, then connect to it from a client. You will be creating two different environments--one for the server and one for the client.

  1. Open two command windows. In each window, change directories to %/demo/programs/simple.
  2. Add %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/bin to the beginning of your path in both windows (or set it globally).
  3. From the directory /frameworks/cloudconnect, copy the following file into /demo/programs/simple:
  4. Make a new (empty) directory in /demo/programs/simple called CloudscapeServer

    You must have both weblogic.properties and a folder called CloudscapeServer in the directory in order to start Cloudconnector. If either of these is missing, Cloudconnector does not start.

    (The directory in which these items live is also known as weblogic.system.home.)

  5. In the server windows, set class path as follows:

    Library or Directory

    Path to Library or Directory

    main Cloudscape library for your product

    (cloudscape.jar or
    cloudsync.jar)

    %CLOUDSCAPE_INSTALL%/lib/NameOfYourLibrary

    current directory

    .

    the Cloudconnector framework classes

    %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/classes/

    %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/lib/weblogicaux.jar

    %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/license/

    A Note on Setting Class Path for a Server Environment

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

  6. In the server window, run Cloudscape's utility for testing the class path for a Cloudconnector environment. You will provide the argument CloudconnectorServer to indicate the environment.

    You run the utility like this:

    java COM.cloudscape.tools.sysinfo -cp arguments

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

    java COM.cloudscape.tools.sysinfo -cp CloudconnectorServer

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

    FOUND IN CLASS PATH:

    Cloudscape primary library (cloudscape.jar or cloudsync.jar)

    Valid Cloudscape license

    Main Cloudconnector libraries (/classes)

    Cloudconnector auxiliary libraries (weblogicaux.jar)

    Cloudconnector license library (/license)

    SUCCESS: All Cloudscape-Related classes for CloudconnectorServer 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 %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/license/ directory, the utility would indicate as such:

    Testing for presence of Cloudscape-related libraries for CloudconnectorServer environment.

    FOUND IN CLASS PATH:

    Cloudscape primary library (cloudscape.jar or cloudsync.jar)

    Valid Cloudscape license

    Main Cloudconnector libraries (/classes)

    Cloudconnector auxiliary libraries (weblogicaux.jar)

    NOT FOUND IN CLASS PATH:

    Cloudconnector license library (/license)

    (/WebLogicLicense.xml not found.)

  7. In the client window, set class path as follows:

    Library or Directory

    Path to Library or Directory

    the client library

    %CLOUDSCAPE_INSTALL%/lib/client.jar

    the Cloudconnector framework classes

    %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/classes/

    %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/lib/weblogicaux.jar

    %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/license/

    current directory

    .

    A Note on Setting Class Path for a Client Environment

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

  8. In the client window, run Cloudscape's utility for testing the class path for a Cloudconnector environment. You will provide the arguments CloudconnectorClient to indicate the environment and CloudscapeSimpleApp.class to test for the presence of that class.

    You run the utility like this:

    java COM.cloudscape.tools.sysinfo -cp arguments

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

    java COM.cloudscape.tools.sysinfo -cp CloudconnectorClient CloudscapeSimpleApp.class

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

    Testing for presence of Cloudscape-related libraries for CloudconnectorClient environment.

    FOUND IN CLASS PATH:

    Cloudscape Client libraries (client.jar)

    Main Cloudconnector libraries (/classes)

    Cloudconnector auxiliary libraries (weblogicaux.jar)

    Cloudconnector license library (/license)

    user-specified class (CloudscapeSimpleApp)

    SUCCESS: All Cloudscape-Related classes for CloudconnectorClient 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 %CLOUDSCAPE_INSTALL%/frameworks/cloudconnect/license/ directory, the utility would indicate as such:

    Testing for presence of Cloudscape-related libraries for CloudconnectorClient environment.

    FOUND IN CLASS PATH:

    Cloudscape Client libraries (client.jar)

    Main Cloudconnector libraries (/classes)

    Cloudconnector auxiliary libraries (weblogicaux.jar)

    user-specified class (CloudscapeSimpleApp)

    NOT FOUND IN CLASS PATH:

    Cloudconnector license library (/license)

    (/WebLogicLicense.xml not found.)

  9. From the server command window, start the server by executing startCS.bat (on Windows) or startCS.ksh (on UNIX). Execute the appropriate startCS command file like this:

    start startCS.bat

    Users on other platforms can execute the command that the file contains instead.

    After starting the server, you should see startup messages from the server. If the server starts successfully, the last message will say:

    ListenThread> Listening on port 7001

  10. In the client window, execute the client program with the following command:

    java CloudscapeSimpleApp sysconnectclient

    The argument sysconnectclient indicates that the application should use the Cloudconnector framework. The application also assumes that the server framework is running on localhost at the default port number. Examine the source code for the application to see how it works.

    A successful run produces the following output:

    CloudscapeSimpleApp starting in sysconnect mode.

    Loaded the appropriate driver.

    Connected to and created database CloudscapeDB

    Created table CloudscapeDB

    Inserted 1956 Webster

    Inserted 1910 Union

    Updated 1956 Webster to 180 Grand

    Updated 180 Grand to 300 Lakeshore

    Verified the rows

    Dropped table CloudscapeDB

    Closed result set and statement

    Committed transaction and closed connection

    CloudscapeSimpleApp finished

  11. Stop Cloudconnector by executing stopCS.bat (on Windows NT) or stopCS.ksh (on UNIX). Go to the client command window and execute the appropriate command:

    stopCS

    Users on other platforms can execute the Java command that the script contains, instead:

    java weblogic.T3Admin t3://localhost:7001 SHUTDOWN system paceesalute

    Stopping the server by typing ^C in the server console window means that Cloudscape will have to run recovery on the database the next time it starts up. Avoid this by using the stopCS command to stop the server framework.

RmiJdbc Framework

In this demo, you will start the RmiJdbc Server, then connect to it from a client. You will be creating two different environments--one for the server and one for the client.

  1. Open two command windows. In each window, change directories to %CLOUDSCAPE_INSTALL%/demo/programs/simple. If you have not already done so, set the CLOUDSCAPE_INSTALL environment variable per the instructions in Getting Started with Cloudscape.
  2. Add %CLOUDSCAPE_INSTALL%/frameworks/RmiJdbc/bin to the beginning of PATH in both windows (or set it globally).
  3. In the server window, set CLASSPATH as follows:

    Library or Directory

    Path to Library or Directory

    main Cloudscape library for your product

    (cloudscape.jar,
    cloudsync.jar)

    %CLOUDSCAPE_INSTALL%/lib/NameOfYourLibrary

    current directory

    .

    the RmiJdbc framework classes

    %CLOUDSCAPE_INSTALL%/frameworks/RmiJdbc/classes/RmiJdbc.jar

    A Note on Setting Class Path for a Server Environment

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

  4. In the server window, run Cloudscape's utility for testing the class path for a RmiJdbc environment. You will provide the argument RmiServer to indicate the environment.

    You run the utility like this:

    java COM.cloudscape.tools.sysinfo -cp arguments

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

    java COM.cloudscape.tools.sysinfo -cp RmiServer

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

    FOUND IN CLASS PATH:

    Cloudscape primary library (cloudscape.jar or cloudsync.jar)

    Valid Cloudscape license

    RmiJdbc server and client libraries (RmiJdbc.jar)

    SUCCESS: All Cloudscape-Related classes for RmiServer 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 %CLOUDSCAPE_INSTALL%/frameworks/RmiJdbc/classes/RmiJdbc.jar file, the utility would indicate as such:

    Testing for presence of Cloudscape-related libraries for RmiServer environment.

    FOUND IN CLASS PATH:

    Cloudscape primary library (cloudscape.jar or cloudsync.jar)

    Valid Cloudscape license

    NOT FOUND IN CLASS PATH:

    RmiJdbc server and client libraries (RmiJdbc.jar)

    (RmiJdbc.RJConnection not found.)

  5. In the client window, set CLASSPATH as follows:

    Library or Directory

    Path to Library or Directory

    the client library

    %CLOUDSCAPE_INSTALL%/lib/client.jar

    the RmiJdbc framework classes

    %CLOUDSCAPE_INSTALL%/frameworks/RmiJdbc/classes/RmiJdbc.jar

    current directory

    .

    A Note on Setting Class Path for a Client Environment

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

  6. In the client window, run Cloudscape's utility for testing the class path for a RmiJdbc environment. You will provide the arguments RmiClient to indicate the environment and CloudscapeSimpleApp.class to test for the presence of that class.

    You run the utility like this:

    java COM.cloudscape.tools.sysinfo -cp arguments

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

    java COM.cloudscape.tools.sysinfo -cp RmiClient CloudscapeSimpleApp.class

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

    Testing for presence of Cloudscape-related libraries for RmiClient environment.

    FOUND IN CLASS PATH:

    Cloudscape Client libraries (client.jar)

    RmiJdbc server and client libraries (RmiJdbc.jar)

    user-specified class (CloudscapeSimpleApp)

    SUCCESS: All Cloudscape-Related classes for RmiClient 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 %CLOUDSCAPE_INSTALL%/frameworks/RmiJdbc/classes/RmiJdbc.jar file, the utility would indicate as such:

    Testing for presence of Cloudscape-related libraries for RmiClient environment.

    FOUND IN CLASS PATH:

    Cloudscape Client libraries (client.jar)

    user-specified class (CloudscapeSimpleApp)

    NOT FOUND IN CLASS PATH:

    RmiJdbc server and client libraries (RmiJdbc.jar)

    (RmiJdbc.RJConnection not found.)

  7. From the server command window, start the server by executing startCS.bat (on Windows) or startCS.ksh (on UNIX). Execute the appropriate startCS command file like this:

    start startCS.bat

    Users on other platforms can execute the command that the file contains instead (all on one line):

    java -ms16m -mx32m RmiJdbc.RJJdbcServer COM.cloudscape.core.JDBCDriver

    After starting the server, you should see startup messages from Cloudscape. If the server starts successfully, the last message will say:

    [RmiJdbc] RmiJdbcServer bound in rmi registry

  8. In the client window, execute the client program with the following command:

    java CloudscapeSimpleApp rmijdbcclient

    The argument rmijdbcclient indicates that the application should use the RmiJdbc framework. The application also assumes that the server framework is running on localhost at the default port number. Examine the source code for the application to see how it works.

    A successful run produces the following output:

    CloudscapeSimpleApp starting in rmijdbc mode.

    Loaded the appropriate driver.

    Connected to and created database CloudscapeDB

    Created table CloudscapeDB

    Inserted 1956 Webster

    Inserted 1910 Union

    Updated 1956 Webster to 180 Grand

    Updated 180 Grand to 300 Lakeshore

    Verified the rows

    Dropped table CloudscapeDB

    Closed result set and statement

    Committed transaction and closed connection

    CloudscapeSimpleApp finished

  9. Stop RmiJdbc server by executing stopCS.bat (on Windows NT) or stopCS.ksh (on UNIX). Go to the client command window and execute the appropriate command:

    stopCS

    Users on other platforms can execute the Java command that the script contains, instead:

    java RJPing jdbc:rmi:jdbc:cloudscape:;shutdown=true;user=;password= connect

    java RJPing jdbc:rmi:jdbc:cloudscape: shutdown

    Stopping the server by typing ^C in the server console window means that Cloudscape will have to run recovery on the database the next time it starts up. Avoid this by using the stopCS command to stop the server framework.