Sample
illustrating use of oracle.jdbc.OracleConnectionWrapper
Table Of Contents
This sample illustrates the use of OracleConnectionWrapper
(oracle.jdbc.OracleConnectionWrapper) class. Use of OracleConnectionWrapper
prevents direct access to OracleConnection. Instead it wraps up
the OracleConnection and routes the JDBC calls from user to OracleConnection.
Since all the JDBC calls have to be made through the wrapper class,
the business logic can be implemented at one place, thus implementing
a single point of control and reducing code duplication.
Sample Application Scenario
The
sample application uses the database tables from oe schema of Oracle9i
Database. This sample application demonstrates the use of oracle.jdbc.OracleConnectionWrapper,
using an Order-Entry Application. The user can perform a maximum
of 10 operations(query or update the status of an order). The number
of operations performed is displayed to the user. When the user
reaches the limit, any further operations are disabled and the user
has to quit the application.
Here is the code usage for Connection Wrapper class. You can find
more details of the code in CustomConnWrapper.java
file under src/oracle/otnsamples/oracle9ijdbc/ConnectionWrapper
folder. Look into Description of Sample
Files section for folder and file details.
|
public class CustomConnWrapper extends oracle.jdbc.OracleConnectionWrapper
{
.......................
// Constructor which takes OracelConnection which is to
be wrapped
public CustomConnWrapper(OracleConnection toBeWrapped
) {
super(toBeWrapped);
}
// Method which intercepts createStatement call to
underlying database
public Statement createStatement() throws SQLException
{
// Business logic - Count the number of statement
objects created
stmtCount++;
return super.createStatement();
}
public PreparedStatement prepareStatement(String sql)
throws SQLException{
// Count the number of PreparedStatement objects created
stmtCount++;
return super.prepareStatement(sql) ;
}
.......................
|
|
This following notations are used through out
this document
|
Notation
|
Description
|
|
<SAMPLE_HOME>
|
Folder where the ConnectionWrapperSample will be unzipped.
|
|
<JAVA_HOME>
|
Folder where JAVA is installed.
|
|
<JDBC_HOME>
|
Folder where the Oracle JDBC driver is installed.
|
|
<ORACLE_HOME>
|
Folder where the ORACLE installed.
|
- Oracle9i JDeveloper (
Note: Oracle9i JDeveloper
is Oracle's Visual Java Development Tool and can be downloaded
from here )
or JDK1.4.x or above This can be downloaded from here .
- Oracle9i Database or higher
running SQL*Net TCP/IP listener. This can be downloaded from here .
- Oracle9i v9.2 JDBC Drivers
for use with JDK 1.4.x , downloadable from OTN
site.
If Oracle9i client is already
installed on your system then this driver need not be downloaded
separately.
-
For setting up environment variables in
different platforms, please refer environment
set up readme document.
- Unjar the provided ConnectionWrapperSample.jar using the following
command
| >
jar xvf ConnectionWrapperSample.jar |
|
Note: You will find jar.exe in <JAVA_HOME>\bin. Ensure <JAVA_HOME>\bin is present in your system path.
This creates a folder ConnectionWrapperSample
with all the source files.
-
Edit ConnectionWrapperSample\Connection.properties file in your favorite editor. Change the HostName,
Port, SID, UserName and Password to connect to your own database.
|
HostName
|
= |
localhost
|
|
SID
|
= |
ORCL
|
|
Port
|
= |
1521
|
|
UserName
|
= |
oe
|
|
Password
|
= |
oe
|
Running the application
using Oracle9i JDeveloper
|
Back To
Top |
This section describes the steps required in
running this application using Oracle9i
JDeveloper.
- Open Oracle9iJDeveloper
and use File/Open option to select the ConnectionWrapperSample.jws
from the ConnectionWrapperSample directory.
- Next, select Project/Make ConnectionWrapperSample.jpr from main menu.
- Set CLASSPATH to Oracle9i
JDBC drivers. It can be done
as follows.
- Select Project/Project settings which displays the Project
settings window
- The options will be displayed in a tree format. Go to
the Library options under the current active coniguration.
- To add Oracle9i
JDBC libraries, Click New button which displays a window
'New Library'.
- Give some name(Oracle JDBC14) in the LIbrary name
field shown.
- Click Edit button at CLASSPATH field which displays
a new window.
- Click 'Add Entry' which displays a File Chooser
window.
- Browse for class lbraries ojdbc14.jar ( In <ORACLE_HOME>/jdbc/lib
of Oracle v9.2 Database or Client instalaltion
)
- Click on Select button
- Click on OK button till you return to Libraries option.
Note : Oracle9i JDeveloper must use
JDK1.4 for compiling and running this sample
So make sure that Oracle9i
JDeveloper uses JDK1.4 for compiling and running this sample.
In order to use JDK 1.4 from Oracle9i
JDeveloper follow the steps below.
- Select Project/Project settings which displays the Project settings
window
-
The options will be displayed in a tree format. Go to the Library
options under the current active coniguration.
- If JDK1.4 is listed in the JDK versions combo box, then
select that. If not, define a new J2SE version for JDK1.4
by providing the location of <JAVA_HOME>/bin/java.exe.
- Now, select Run/Run
ConnectionWrapperSample.jpr from main menu which opens up the browser and runs the
ConnectionWrapperSample.
|