WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

Package examples.jdbc.oracle.extensions

This example demonstrates the usage of SQL3 datatypes in server-side applications with an Oracle database.

See:
          Description

Interface Summary
Extensions  
ExtensionsHome  
 

Class Summary
AddressBO This class represents an address.
ArraysClient This client is the starting point to demonstrate Oracle ARRAY.
ArraysDAO This simple example shows how to use Oracle ARRAYs.
BaseClient Common client functions.
BaseDAO This class provides common database methods.
EmployeeBO This class represents an employee.
ExtensionsBean This class contains logic for the extension ejb.
RefsClient This client is the starting point to demonstrate Oracle REF.
RefsDAO This simple example shows how to use Oracle REFs.
StructsClient This client is the starting point to demonstrate Oracle STRUCT.
StructsDAO This simple example shows how to use Oracle STRUCTs.
 

Package examples.jdbc.oracle.extensions Description

This example demonstrates the usage of SQL3 datatypes in server-side applications with an Oracle database. The sample applications use the supported Oracle extension methods for STRUCTs, REFs, and ARRAYs. To run this example, you must use a connection pool and the Oracle Thin driver.

Note: You can use STRUCTs, REFs, and ARRAYs in server-side applications only.

 
Additional Resources for examples.jdbc.oracle.extensions
build.xml The Java Ant build script, which assembles and deploys required EJBs and client applications for this example. It also includes targets for preparing your database and running the example.
table.ddl SQL code used by the Java Ant db_setup_oracle script to create tables and objects in your database.

 

This example uses three client applications to demonstrate retrieving and inserting STRUCTs, and retrieving REFs and ARRAYs:

You compile this example with a single script and then run each client individually. Before you run the example, read through the source code files to get familiar with what actually happens in the example.

To facilitate this example, you create a connection pool and datasource to connect to your Oracle database. You also create the following object types and tables in your database via an ant script:

 

The following sections describe how to build and run the example.

  1. Prerequisites
  2. Configure the Server
  3. Build the Example
  4. Prepare the Database
  5. Run the Example
  6. Check the Output

 

Prerequisites

Before you run this example, you need:

 

Configure the Server

The following procedure shows how to set up a connection pool and Tx datasource to use to connect to your Oracle database.
  1. Start the server with the examples configuration in a new command shell.

  2. Start the Administration Console. Refer to Configuring JDBC Connectivity Using the Administration Console for detailed information on configuring connection pools and transaction datasources.

  3. Configure the oraclePool connection pool and assign it to the examplesServer:

  4. Configure the examples-dataSource-oracleXAPool transaction datasource and assign it to the examplesServer:

 

Build the Example

To build the example, follow these steps:
  1. Open a command shell.
  2. Set up the command shell as described in Setting up Your Environment.
  3. Add the path to your BEA_HOME and to the Oracle Thin Driver classes (classes12.zip) to your CLASSPATH. For example:
    set CLASSPATH=c:\bea;%WL_HOME%\server\lib\classes12.zip;%CLASSPATH%
  4. Add the path to the WebLogic jDriver for Oracle classes (e.g., oci817_8 folder) to your PATH. For example:
    set PATH=%WL_HOME%\server\bin\oci817_8;%PATH%
  5. Change to the %SAMPLES_HOME%\server\src\examples\jdbc\oracle\extensions directory.
  6. Execute the following command:
      ant

When you run the ant script to build the example, it builds all three clients in the example.

 

Prepare the Database

  1. In the %SAMPLES_HOME%\server\src\examples.properties file, specify a value for the following properties:

    The Ant db_setup_oracle script uses these properties when creating tables and objects in your database.

    Note: You must have a matching entry for the database in tnsnames.ora. See Setting Up Examples to Run with an Oracle DBMS for more details.
     

  2. Open a command shell.
  3. Set up the command shell as described in Setting up Your Environment.
  4. Change to the %SAMPLES_HOME%server\src\examples\jdbc\oracle\extensions directory.
  5. Execute the following command:
     ant db_setup_oracle

    The script creates the required object types and tables in your database.

For more information about setting up your database, see Setting Up Examples to Run with an Oracle DBMS.

 

Run the Example

  1. Open a command shell.
  2. Set up the command shell as described in Setting up Your Environment.
  3. Add the path to your BEA_HOME and to the Oracle Thin Driver classes (classes12.zip) to your CLASSPATH. For example:
    set CLASSPATH=c:\bea;%WL_HOME%\server\lib\classes12.zip;%CLASSPATH%
  4. Add the path to the WebLogic jDriver for Oracle classes (e.g., oci817_8 folder) to your PATH. For example:
    set PATH=%WL_HOME%\server\bin\oci817_8;%PATH%
  5. Change to the %SAMPLES_HOME%\server\src\examples\jdbc\oracle\extensions directory.
  6. Execute the following commands:

 

Check the Output

STRUCTs

When you run the STRUCTs client, you should see the following output in the command shell:

Buildfile: build.xml

run_structs:
     [java] Getting employees from database...
     [java] Employee#: 100
     [java] Name:      Alfred Chuang
     [java] Address: 1234 Post St
     [java]          San Francisco, CA
     [java]
     [java] Employee#: 101
     [java] Name:      Joe Walker
     [java] Address: 3321 Grand Ave
     [java]          San Diego, CA
     [java]
     [java] Employee#: 102
     [java] Name:      Tina Potter
     [java] Address: 7111 Ocala St
     [java]          Tallahassee, FL
     [java]
     [java] Employee#: 103
     [java] Name:      Fred Couples
     [java] Address: 9201 Park St
     [java]          Alexandria, VA
     [java]
     [java]
     [java] Inserting employee to database...
     [java]
     [java] Getting employees from database...
     [java] Employee#: 100
     [java] Name:      Alfred Chuang
     [java] Address: 1234 Post St
     [java]          San Francisco, CA
     [java]
     [java] Employee#: 101
     [java] Name:      Joe Walker
     [java] Address: 3321 Grand Ave
     [java]          San Diego, CA
     [java]
     [java] Employee#: 102
     [java] Name:      Tina Potter
     [java] Address: 7111 Ocala St
     [java]          Tallahassee, FL
     [java]
     [java] Employee#: 103
     [java] Name:      Fred Couples
     [java] Address: 9201 Park St
     [java]          Alexandria, VA
     [java]
     [java] Employee#: 105
     [java] Name:      David David
     [java] Address: 4431 Canal Street
     [java]          New Orleans, LA
     [java]

BUILD SUCCESSFUL
If you check the command shell running the server, you should see the following:
StructsDAO.getEmployees() -- Number of rows selected: 4
BaseDAO.getNextId() -- Next employees_seq id is 105
StructsDAO.insertEmployee() -- Number of rows inserted: 1
StructsDAO.getEmployees() -- Number of rows selected: 5

 

REFs

When you run the REFs client, you should see the following output in the command shell:

Buildfile: build.xml

run_refs:
     [java] Getting refs from database...
     [java]
     [java] See server output for results.

BUILD SUCCESSFUL
Check the command shell running the server to see the following:
RefsDAO.getAddresses() -- Id = 1001, Name = Alfred Chuang, Address Id = 100, Street = 1234 Post St, City = San Francisco, State = CA
RefsDAO.getAddresses() -- Id = 1002, Name = Joe Walker, Address Id = 101, Street = 3321 Grand Ave, City = San Diego, State = CA
RefsDAO.getAddresses() -- Id = 1003, Name = Fred Couples, Address Id = 102, Street = 9201 Park St, City = Alexandria, State = VA

 

ARRAYs

When you run the ARRAYs client, you should see the following output in the command shell:

Buildfile: build.xml

run_arrays:
     [java] Getting arrays from database...
     [java]
     [java] See server output for results.

BUILD SUCCESSFUL
Check the command shell running the server to see the following:
ArraysDAO.getStudents() -- Id = 100, Student = Trey Anastasio
   Test1 = 100
   Test2 = 87
   Test3 = 90
   Test4 = 89
   Test5 = 99
ArraysDAO.getStudents() -- Id = 101, Student = Mike Gordon
   Test1 = 89
   Test2 = 76
   Test3 = 100
   Test4 = 80
   Test5 = 85
ArraysDAO.getStudents() -- Id = 102, Student = Page McConnell
   Test1 = 100
   Test2 = 100
   Test3 = 95
   Test4 = 98
   Test5 = 75
ArraysDAO.getStudents() -- Id = 103, Student = Jon Fishman
   Test1 = 55
   Test2 = 70
   Test3 = 76
   Test4 = 60
   Test5 = 75

 

See Also

Read more about using SQL3 datatypes and Oracle extension methods with WebLogic Server in:


Documentation is available at
http://e-docs.bea.com/wls/docs70

Copyright © 2002 BEA Systems, Inc. All Rights Reserved.