Simple JDBC Application,
Page 1 of 1



Documentation Top
Global Index
Top of Demos

Simple JDBC Application

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

  • starts up the Cloudscape engine, if necessary
  • creates and connects to a database
  • creates a table
  • inserts data
  • updates data
  • selects data
  • drops a table
  • disconnects
  • shuts down Cloudscape, if necessary

The application can run in any of the following environments:

  • embedded
    This is the simplest Cloudscape environment. The application starts up an instance of Cloudscape within the current JVM and shuts down the instance before it completes. No network access is involved. In an embedded environment, only one application at a time can access a database.
  • client/server
    The application connects to Cloudscape over the network. Cloudscape is already running embedded in a connectivity or server framework that allows multiple network connections. This application can use either of the following frameworks:
    • Cloudconnector (to use this framework, you must have already purchased Cloudconnector)
    • RmiJdbc (a lightweight JDBC server and client provided with Cloudscape)

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:

  • example.html
    This file.
  • CloudscapeSimpleApp.java
    Source code for the example program that starts up Cloudscape, creates a database, does some inserts and updates, and then shuts down Cloudscape. Examine this file to see how the application behaves in the various environments.
  • cloudscape.properties
    Properties file for the Cloudscape system.
  • CloudscapeSimpleApp.class
    The compiled class file.

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

  • CloudscapeDB (directory)
    The directory that makes up the CloudscapeDB database. You must not modify anything in this directory, or you will corrupt the database. The directory was created when the application connected with Cloudscape, using the attribute create=true in the database connection URL. The database name, CloudscapeDB, was also set in the database connection URL.
  • CloudscapeDB\log (directory)
    The directory that holds the database log for the CloudscapeDB database.
  • CloudscapeDB\seg0 (directory)
    The directory that holds the data for the CloudscapeDB database.
  • CloudscapeDB\service.properties
    An internal file that holds boot-time configuration parameters for the CloudscapeDB database; do not edit.
  • cloudscape.LOG
    The log file with Cloudscape progress and error messages.
  • CloudscapeDB\cloudscape.db
    An identifying file for file finders.
  • files specific to Cloudconnector, if that framework is used

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

    license library, if you are working with the 30-day evaluation product

    %CLOUDSCAPE_INSTALL%/lib/license.jar

    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. Note that you may need to add the license.jar file.

  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)

    Cloudscape license (for evaluation customers, this is in license.jar; for other customers, this is in the main cloudscape library)
    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)

    Cloudscape license (for evaluation customers, this is in license.jar; for other customers, this is in the main cloudscape library)

    NOT FOUND IN CLASS PATH:
    user-specified class (CloudscapeSimfleApp)
    (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:
    • weblogic.properties (a file)
  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

    license library, if you are working with the 30-day evaluation product

    %CLOUDSCAPE_INSTALL%/lib/license.jar

    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. Note that you may need to add the license.jar file.

  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)

    Cloudscape license (for evaluation customers, this is in license.jar; for other customers, this is in the main cloudscape library)

    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)


    Cloudscape license (for evaluation customers, this is in license.jar; for other customers, this is in the main cloudscape library)


    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)


    Cloudconnector license library (/license)


    user-specified class (CloudscapeSimpleApp)


    SUCCESS: All Cloudscape-Related classes for CloudconnectorClient environment found in class path.

  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

    license library, if you are working with the 30-day evaluation product

    %CLOUDSCAPE_INSTALL%/lib/license.jar

    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. Note that you may need to add the license.jar file.

  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)


    Cloudscape license (for evaluation customers, this is in license.jar; for other customers, this is in the main cloudscape library)


    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)

    Cloudscape license (for evaluation customers, this is in license.jar; for other customers, this is in the main cloudscape library)


    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 two messages will say:
    COM.cloudscape.core.JDBCDriver registered in DriverManager /RmiJdbcServer bound in rmi registry

    Users on other platforms can execute the command 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 two messages will say:
    COM.cloudscape.core.JDBCDriver registered in DriverManager /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 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 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.



Cloudscape Version 3.0
For technical support, go to: www.cloudscape.com and click Support.
Copyright © 1998 and 1999 Cloudscape, Inc. All rights reserved.