Rooms Information - Java Stored Procedure Sample

Table of Contents

Overview of the Sample Application 

Back To Top

This Sample Application demonstrates how to access a Java Stored Procedure using JDBC. Stored procedures are Java methods published to SQL and stored in an Oracle database for general use. To publish Java methods, you write call specifications (call specs for short), which map Java method names, parameter types, and return types to their SQL counterparts.

When this sample application is run a list of hotels is displayed. The user can select a hotel and get information about the rooms in the hotel selected. The rooms information is obtained by calling the Java Stored Procedure get_room_details.The Java method getRoomDetails available in RoomsInformationProcedure.java file is published to the Oracle database. 'GET_ROOM_DETAILS' is the call specification that maps Java method name, its parameter types, and return types to its SQL counterpart.


Required Software 

Back To Top

Calling Program

1.Oracle9i JDeveloper (Note: JDeveloper is Oracle's Visual Java Development Tool and can be downloaded from here )
or
JDK 1.2 or higher (can be downloaded from here)

2. Oracle9i Client complete installation (can be downloaded from here)

Host

1. Oracle9i Database or higher running SQL*Net TCP/IP listener (can be downloaded from here )

2. Travel Schema needs to be loaded into the database. (can be downloaded from here)

 

Extracting the Sample

Back To Top

Unjar RoomsInformationSample.jar using Winzip, or using the following command
jar xvf RoomsInformationSample.jar

Make sure that jar.exe available at <jdev_home>\jdk\bin (while using JDeveloper) or <jdk_home>\bin (while using JDK)
is present in your system path.

Refer Description of Sample Files section for more details. 

Preparing and Running the Sample

Back To Top

Following are the two ways for Preparing and Running the Sample:

1. Using JDK Environment

2. Using Oracle9i JDeveloper

Using JDK Environment

Back To Top

1.

Ensure that loadjava.exe available at <oracle_home>\bin is available in the system path.<oracle_home> refers to the directory where Oracle9i client is installed.
On Command Prompt, type the following command

% loadjava -user travel/travel@HostName:Port:SID -verbose -force -resolve -thin <your_directory_structure>\RoomsInformationSample\src\oracle\otnsamples\jsp\
roomsinformationsample\RoomsInformationProcedure.java
Where

HostName

Database Machine Name (e.g. insn104a.idc.oracle.com)

Port

TNS listener port (eg: 1521)

SID

Database name (e.g ORCL)

2.

Connect to your database using the command
% sqlplus travel/travel@<DatabaseConnectString>
where <DatabaseConnectString> is your TNSName

3.

Run the script RoomsInformationSample\config\DatabaseSetup.sql at the  SQL prompt
@<your_directory_structure>\RoomsInformationSample\config\DatabaseSetup.sql
This creates a database stored procedure GET_ROOM_DETAILS.

4.

Edit Connection.properites file. Change the hostname, SID, and portnumber to that of the database instance you want to connect to.

For eg.

HostName

= insn104a.idc.oracle.com

SID

= ora9idb

Port

= 1522

UserName

= travel

Password

= travel

5.

Install Oracle JDBC Driver and include the classes12.zip file in the CLASSPATH. Also ensure <your_directory_structure>\RoomsInformationSample\src and <your_directory_structure>\RoomsInformationSample\config are set in the CLASSPATH.

6.

On command prompt, navigate to <your_directory_structure>\RoomsInformationSample.Compile all the source files used in this sample application using:
%javac src\oracle\otnsamples\jsp\roomsinformationsample\*.java

7.

Run the 'RoomsInformationSample' class file using java:
%java oracle.otnsamples.jsp.roomsinformationsample.RoomsInformationSample


Using Oracle9i JDeveloper

Back To Top

1.

Using Oracle9i JDeveloper, File/Open option select the RoomsInformationSample.jws from the RoomsInformationSample directory.

2.

Edit Connection.properties file. Change the hostname, SID, and portnumber to those of the database instance you want
to connect to.

For eg.

HostName

= insn104a.idc.oracle.com

SID

= ora9idb

Port

= 1522

UserName

= travel

Password

= travel

3.

To create the deployment profile, click File-> New-> Deployment Profiles -> LoadJava and Java Stored Procedure.
Save the Deployment Profile file with the default name given for the deployment file.

4.

In the 'LoadJava and Java Stored Procedure Deployment Profile Settings', deselect all the files except 'RoomsInformationProcedure.java' as shown in the figure. 1.1. On clicking 'OK' the deployment profile would appear in the Oracle9i JDeveloper Navigator window.

Figure 1.1 ScreenShot Displaying the LoadJava and JavaStored Procedure Deployment Screen

5.

Right click on the Deployment Profile created, select 'Add Stored Procedure' for publishing the Stored Procedures. Choose 'getRoomDetails' method from the displayed list.

6.

Click 'Settings' button. Give 'GET_ROOM_DETAILS' as the name by which it will be published. Also in the PL/SQL parameter settings change the mode as 'OUT' for 'P3', 'P4' parameters which are of type 'Array' as shown in figure 1.2. Click OK till all windows are closed.

Figure 1.2 Screenshot for method setting while publishing

7.

To deploy the 'Get_Room_Details' stored procedure to the database,
i) Right click on the Deployment Profile,
ii) Select the 'Deploy To' option choose the database connection to which you want to deploy the Stored Procedures if database connection already exists
iii) Else create a database connection by right clicking on the Deployment Profile->Deploy to ->New Connection.
iv) Enter connection name, Connection type as Oracle JDBC, click 'Next' enter Username and Password of the user in which Travel schema is installed.click 'Next', Select 'Driver as 'Thin',enter Hostname, JDBC Port and SID .Click 'Finish'. This creates a database connection and also completes the deployment.

8.

To run the application, select Run/Run RoomsInformationSample.jpr from Oracle9i JDeveloper main menu.


Steps in the Sample

Back To Top

Step 1.

The user invokes the application, and the application displays the connection status or any errors in the status bar.

Step 2.

If the connection was successful, the application will  display all hotels as shown in figure 1.3

Figure 1.3 ScreenShot Displaying List of Hotels

Step 3.

Then the  user has to select a hotel and  click  'Room Enquiry' button to get the room details. The room details are displayed as shown in figure 1.4

Figure 1.4 Screenshot Displaying Room Information

Step 4.

 When the user click the "EXIT" button, the application exits.

 

Description of Sample Files 

Back To Top

Directory

File Name

Description

RoomsInformationSample\src\oracle\
otnsamples\jsp\roomsinformationsample

RoomsInformationSample.java 

The source file for sample

RoomsInformationFrame.java 

The source file for the sample User Interface

RoomsInformationProcedure.java

This file contains the Java Stored  Procedure implementation

GenTableModel.java

The source file for the GenTableModel class, which handles the JTable data.

RoomsInformationSample\doc

Readme.html

This file

RoomsInformationSample\doc\images

*.gif

This directory contains screenshots used in the file Readme.html

RoomsInformationSample\config

Connection.properties

This file contains the Database connection parameters

DatabaseSetup.sql

This file creates the database stored procedure.

RoomsInformationSample\

RoomsInformationSample.jws

Oracle9i JDeveloper workspace file

RoomsInformationSample.jpr

Oracle9i JDeveloper project file

Logo.gif

Image file used in the sample application


Please enter your comments about this sample in the OTN Sample Code Discussion Forum.

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy