Sample Illustrating Oracle9i JDBC OCI Transparent Application Failover Callbacks.Table Of Contents
Transparent Application Failover (TAF) or simply Application Failover is a feature of the OCI driver. It automatically reconnects to a database if the database instance to which the connection is made goes down. In this case, the active transactions roll back. (A transaction rollback restores the last committed transaction.) The new database connection, though created by a different node, is identical to the original. This is true regardless of how the connection was lost. This sample demonstrates the registration and operation of Oracle9i JDBC OCI application failover callbacks by registering a callback function with the connection. The application connects to the database and spawns a thread, which runs for infinite. In this thread, the count of total no of Orders from the Orders table is inserted as a row in the table Order_Data. Then the thread sleeps for 5 second. Now, to demonstrate the Transparent Application Failover (TAF) feature, the database is forcefully shutdown (ABORT). In this application, the following events are captured :
Steps in the SampleStep 1: To demonstrate the functionality, compile and start up the sample. (as explained in the below sections) Step 2: Log into sqlplus and connect /as sysdba. Step 3: While the sample is still running, shutdown the database with "shutdown abort". At this moment, the failover callback functions will be invoked. Step 4: The failover events will be captured and the respective messages are displayed. Step 5: The database can be restarted using "startup", and the interrupted query will be continued. Here is the code explaining Transaction Failover Call back Function. You can find more details of the code in OCIdriverTAFSample.java file under src\oracle\otnsamples\oracle9ijdbc\ocitaf folder. Look into Description of Sample Files section for folder and file details.
This following notations are used through out this document
Note: You will find jar.exe in <JAVA_HOME>\bin. Ensure <JAVA_HOME>\bin is present in your system path. For setting up environment
variables in different platforms, please refer environment
set up readme document
Database Setup
|
Running the application from command line |
Back To Top |
This section describes steps to run the application from
console using JDK for Windows and Redhat Linux Advanced
Server version 2.1. This application can be run either manually
or using a script file.
Run the application using script file :
- Make sure that the environment variables[<JAVA_HOME> and <JDBC_HOME>] have been set before proceeding futher. For more information on how to setup these environment variables in different platforms, please refer environment set up readme document
- If JDK 1.4 is used, then ojdbc14.jar(downloadable from OTN) must be used. For all other JDK versions, classes12.jar must be used. .
- Now the sample application can be directly run by just executing the script file: run.bat/run.sh from the command prompt, from OCIdriverTAFSample directory.
- Execute the script file in Windows as follows
D:\OCIdriverTAFSample\run
For Redhat Linux Advanced Server version 2.1 environment, execute the script file as follows:
$sh run.sh
Running the application manually:
- Set CLASSPATH to include Oracle9i JDBC Driver file: classes12.zip or classes12.jar or ojdbc14.jar
. For more information on how to setup environment variables in different platforms, please refer environment set up readme document
- Also add <SAMPLE_HOME>\OCIdriverTAFSample directory where Connection.properties exists and current directory to the CLASSPATH
- Make sure that <JAVA_HOME>/bin is in the path.
Note :If JDK 1.4 is used, then ojdbc14.jar(downloadable from OTN) must be used. For all other JDK versions, classes12.jar must be used.
- From the directory <SAMPLE_HOME>\OCIdriverTAFSample\src\oracle\otnsamples\oracle9ijdbc\ocitaf, compile all the java files using javac:
Example:
javac -d . *.java
- Run the class file using java
Example:
java oracle.otnsamples.oracle9ijdbc.ocitaf.OCIdriverTAFSample
Description of Sample Files |
Back To Top |
The directory structure of the deliverable OCIdriverTAFSample.jar
will be as shown below. OCIdriverTAFSample
is the top level directory
|
|
|
|
| OCIdriverTAFSample | OCIdriverTAFSample.jws | The Oracle9i JDeveloper workspace file |
| OCIdriverTAFSample.jpr | The Oracle9i JDeveloper project file | |
| Connection.properties | This file has the details of the database connection parameters | |
| run.bat | The batch file to compile and run the sample in Windows environment | |
| run.sh | The shell script file to compile and run the sample in Linux environment | |
| OCIdriverTAFSample\database | OCIdriverTAFSample.sql | This file creates the tables required by the sample . |
| OCIdriverTAFSample\src\oracle\otnsamples\oracle9ijdbc\ocitaf | OCIdriverTAFSample.java | The Source file for the Sample |
| OCIdriverTAFFrame.java | The Source file for the sample User Interface | |
| QueryThread.java | The source file which runs the thread to query database tables. | |
| GenTableModel.java | The source file for the GenTableModel class, which handles the JTable data. |
1. "java.lang.UnsatisfiedLinkError: no ocijdbc9 in java.library.path",
while running under Linux Environment
Check if LD_LIBRARY_PATH is set to $ORACLE_HOME\lib. If JDeveloper
is used, open the JDeveloper in the shell where this variable is set.
2. "java.lang.NoSuchFieldError: envCharSetId", use the classes12.jar from <ORACLE_HOME>\jdbc\lib.