ThreadSample Illustration
This sample illustrates the use of threads in a JDBC application. Java
Threads is a native java feature using which, two paths of execution The aim of this application is to illustrate the typical use of Java Threads in a database application. It retrieves all the rows from AVAILABLE_ROOM_TYPES table, displays the rows and also computes the average rate and total number of rooms of each type. The database retrieval is done in one thread and the display and computation in another. The computation thread also performs a database operation (a join to get the hotel name from the hotel id). This application uses the JDBC-Thin driver to connect to the database.
JDBC-OCI driver can be used after changing the database URL. Steps in the Sample
The section has a set of for step-by-step instructions to run this application successfully. This will be discussed in the following subsections Run the sample using Oracle9i JDeveloper Run the sample using the JDK environment Install the sample Step 1. Unjar ThreadSample.jar
using the following command: > jar xvf ThreadSample.jar You will find jar.exe in JDK_HOME\bin. Make sure jar.exe is present in your system path. (JDK_HOME is the root directory of the JDKx.x installation ). This creates a folder ThreadSample with all the source files Step 2. Edit Connection.properties file located in the directory ThreadSample . Change the host name, port number and database name to those of the database instance you want to connect to.
Database SetupThe application requires the Travel Schema to be loaded into the database. Run the sample using Oracle9i JDeveloperStep 1. Using JDeveloper File/Open option select the ThreadSample.jws from the ThreadSample directory. Step 2. Select Project/Make from JDeveloper main menu and select Make Project "ThreadSample.jpr" Step 3. Select Run/Run<ThreadSample.jpr>
from JDeveloper main menu to run the application. Run the sample using the JDK Environment Step 1. Install
Oracle JDBC Driver and include the zip/jar files in the CLASSPATH. Oracle
JDBC 2.0 compliant drivers can be downloaded from Oracle
Technology Network. Make
sure that Connection.properties in the classpath
%javac *.java
ThreadSample is the top level directory.
Please enter your comments about this sample in the OTN Sample Code Discussion Forum. |