Sun Microsystems Logo

 

 

Sun[tm] ONE Application Server 7 Samples
Using Oracle with the Samples

The sample applications included in the Sun ONE Application Server are configured to work with the bundled PointBase Network Server 4.2. The PointBase database is  prepopulated with data for the samples. More information on using PointBase with the samples can be found in the Using PointBase with the Samples document. The purpose of this document is to outline the steps needed to configure the samples environment to work with an Oracle RDBMS.

This document contains instructions to configure the Oracle  JDBC driver, an example using the jdbc-simple sample application to demonstrate steps involved in using Oracle instead of Pointbase and a list of samples that contain Oracle-specific instructions. The samples included in this list contain specific instructions for configuring the sample to work with an Oracle RDBMS.  For other applications, use the jdbc-simple example as a template to set up Oracle as the database. This document also addresses special cases.

To learn about basic operations with Oracle and the Sun ONE Application Server, read the following sections:

  » Configuration and Set Up Instructions
  » Running the JDBC Simple Application with Oracle
  » Samples with Oracle instructions
  » Special Considerations
  » Troubleshooting and Notes

Configuration and Set Up Instructions

Configure Sun ONE Application Server with Oracle Type 4 JDBC Driver

You can add the Oracle JDBC driver to the application server classpath by either:

  • Copying the driver library to the application server instance's lib/ directory which is <domain_config_dir>/domain1/server1/lib. All the libraries in this directory are automatically added to the server's classpath during restart. Or,
  • Adding the driver's path to the Classpath Suffix setting under the application server instance's JVM Settings -> Path Setting area in the administrative console.

In both cases, the application server must be restarted to update the classpath.

If you are using a Type 2 driver, you will also need to add <oracle_home>/lib to the Native Library Path Suffix setting in the application server instance's JVM Settings -> Path Settings area.

Create the Database Users and Schemas for the Sample Application

The following steps assume that you have access to a running Oracle RDBMS. Note that the user creation script will drop any existing users with the same name.

Use <install_dir>/samples/docs/cr_ora_user.sql to create specific sample oracle user. This script will create the user on the specified tablespace.

Using sqlplus, login as system/manager:

<SQL> @cr_ora_user.sql user_name password tablespace_name

    user_name:
    The following username and password are consistent with the naming convention used for PointBase. Generally, all samples in one category (e.g. ejb/bmp) will contain one Oracle user (bmp).

                     Sample            User         Password
              Java Pet Store       petstore      petstore
          opc      opc
          supplier      supplier
              JDBC samples       jdbc      jdbc
              Lifecycle samples       lifecycle      lifecycle
              EJB/CMP samples       cmp      cmp
              EJB/BMP samples       bmp      bmp
              EJB/Subclassing samples             subclass           subclass
             Transactions       transactions      transactions
             Smart Ticket       smarticket      smarticket
             Duke's Bank       dukesbank      dukesbank
             Webapps/BookStore samples       bookstore      bookstore


    tablespace_name:
    If you want to create a separate tablespace for all samples, you can use the <install_dir>/samples/docs/cr_ora_tb.sql script. If you don't want to create the new tablespace, you can use the sql command "select tablespace_name, status from DBA_TABLESPACES" to see the available online tablespaces (run this sql command as system/manager). 

Use sqlplus with the user created above and run the SQL script under <sample_app_dir>/sql to load the database schema for this sample.

When there is only one .sql file, it works with both Oracle and PointBase.

Modify Sample's build.xml File
  1. Add one Ant target:
    <target name="setup_ora" depends="setup_env, deploy_jdbc_resource_ora_common, reconfig"/>
  2. Add two properties, conpool.name and jdbc.resource.name if they are not already defined in the build.xml file. Refer to Table 2 to see which sample needs these two properties.
  3. Remove the two properties, ds.class and url.prop if they are defined in the build.xml file.
Compile and Deploy the Application

If the application has been deployed previously with a PointBase configuration:

asant undeploy
asant setup_ora -Ddb.host=[db_hostname] -Ddb.port=[db_port] -Ddb.sid=[sid]
asant deploy_common

You need to restart the application server if the application ran previously with Pointbase.

If this is the first time the application has been deployed:

asant core
asant setup_ora -Ddb.host=[db_hostname] -Ddb.port=[db_port] -Ddb.sid=[sid]
asant deploy_common

Running the JDBC Simple Application with Oracle

Here are the detailed steps to configure the JDBC Simple sample application sample to work with Oracle:

1. Use sqplus and login as system/manager to create oracle user jdbc/jdbc on the specified tablespace.

2. Using sqlplus, using the user 'jdbc', load the schema using the jdbc-simple-ora.sql file located in <install_dir>/samples/jdbc/simple/src/sql. This step will load the schema for jdbc-simple application in Oracle


    <SQL> @jdbc-simple-ora.sql

3. Go to <install_dir>/samples/jdbc/simple/src. In the build.xml file, ensure that the following properties and Ant target are defined:


    <property name="conpool.name"       value="jdbc-simple-pool" />
    <property name="jdbc.resource.name" value="jdbc/jdbc-simple" />
    <target name="setup_ora" depends="setup_env, deploy_jdbc_resource_ora_common, reconfig"/>

4. Compile and Deploy (undeploy first, if it was deployed already )

    asant core
    asant undeploy (optional)
    asant setup_ora -Ddb.host=sx450.red.iplanet.com -Ddb.port=1521 -Ddb.sid=bx3
    asant deploy_common

5. Run the application (refer to sample application's document)

Samples with Oracle Instructions

The following applications contain the necessary sql files and ant targets (build.xml) to work with Oracle.  Refer to the sample documentation for Oracle specific instructions.
  » Java Pet Store
  » Smart Ticket
  » Duke's Bank
  » transactions/web/simple
  » security/realms/rdbms
  » ejb/cmp/simple

Special Considerations

ejb/cmp/roster application

    Ant target "setup_ora" has one more dependency. The target should resemble the following:

    <target name="setup_ora" depends="setup_env, deploy_jdbc_resource_ora_common, create-persistence-resource, reconfig"/>

webapps/bookstore application

Both bookstore1 and bookstore2 share the same sql file and jdbc-resources. The sql script is:

<install_dir>/samples/webapps/bookstore/common/sql/bookstore.sql

lifecycle/jdbc application and lifecycle/multithreaded

  • If the application has been deployed previously with PointBase:

    asant undeploy_jdbc_resource
    asant setup_ora -Ddb.host=[db_hostname] -Ddb.port=[db_port] -Ddb.sid=[sid]

    You need to restart the app server if the application was executed against PointBase.

  • If the sample had not been executed previously:

    asant deploy
    asant undeploy_jdbc_resource
    asant setup_ora -Ddb.host=[db_hostname] -Ddb.port=[db_port] -Ddb.sid=[sid]

The following samples require you to define conpool.name and jdbc.resource.name properties:

    Application Name
    Connection Pool Value
    JDBC Resource Value
    JDBC/BLOB
    jdbc-blobPool
    jdbc/jdbc-blob
    JDBC/Transactions
    jdbc-transactionsPool
    jdbc/jdbc-transactions
    Lifecycle/JDBC
    jdbc-lifecyclePool
    jdbc/lifecycle-jdbc
    Transactions/EJB/teller
    LocalPoolteller
    jdbc/transactions-teller/TellerDB
    Transactions/WEB/bank
    LocalPoolbank
    jdbc/transactions-bank/BankDB

Troubleshooting and Notes

Connector/cci Sample: There is a known bug when attempting to use this sample with Oracle. See the release notes for details.

JDBC/Blob Sample:  If the Type 4 JDBC driver is used as explained in this document, the uploaded file cannot exceed 5K. The workaround is to use Type 2 OCI driver. Here are the steps to setup the driver:

1. In the administrative console, modify the property for connection pool jdbc-blobPool. The value of url property should be: jdbc:oracle:oci8@db_alias (db_alias should be defined in TNS).

2. Either copy the Type 2 driver to the application server instance's lib/ directory or add the path to the driver to the Classpath Suffix setting in the JVM Settings -> Path Settings area of the administrative console.

3. Modify the Native Library Path Suffix setting in the application server instance's JVM Settings -> Path Settings area to include the path <oracle_home>/lib.

4. Apply the changes and restart the application server.