DBA Tips Archive for Oracle
JServer / Thin Driver Connection Manager for Oracle
by Jeff Hunter, Sr. Database Administrator
Since the release of Oracle8i, Oracle application developers have had the option of deploying their code either inside the database (using the JServer option) or outside of the database (using either the thin or oci8 drivers).Demonstrate using the Thin Driver
When designing code to run outside the database, the application developer will choose a JDBC connection as follows:
- Selecting the oci driver, you would use the JDBC connection string "jdbc:oracle:oci"
- Selecting the pure-Java thin driver, you would use the JDBC connection string "jdbc:oracle:thin"
However, code running inside the Oracle database uses a special, in-memory JDBC driver implementation called the JServer Native Driver whose JDBC connection string can be set to either "jdbc:default:connection:" or "jdbc:oracle:kprb:". Code executing inside the database is already running in the context of the currently connected database user and therefore requires no username or password.
Examples of complete JDBC connection strings using the above three drivers are:
This article provides example code and the steps necessary to create a "helper class" (called OracleConnection) that isolates the connection details from application code. The OracleConnection class will provide a static method that can be used by Java applications to make a database connection whether inside or outside the database.
javac OracleConnection.java TestThinConnection.java
Helper Class Source Code: OracleConnection.javaOracleConnection.java is a help class that can be used by any Java program to connect to the database whether running inside or outside the database. Testing the Thin Driver: TestThinConnection.javaTestThinConnection.java is a small Java program that uses the helper class OracleConnection to make its connection to the database.TestThinConnection.outExample output of TestThinConnection. Testing the JServer Driver: TestJServerConnection.javaTestJServerConnection.java is a small Java program that uses the helper class OracleConnection to make its connection to the database.LoadJServer.shLoadJServer.sh is a UNIX shell script that can be used to Load/Compile both the OracleConnection helper class and the testing example application TestJServerConnection into the Oracle Database.CallSpecJServer.sqlCallSpecJServer.sql is used to create the "Call Specs" needed for the example JServer_mgr Testing Application.RunJServer.sqlThe RunJServer.sql script can be used to run the JServer_mgr.show_user() method.TestJServerConnection.outExample output of TestJServerConnection.
Copyright (c) 1998-2018 Jeffrey M. Hunter. All rights reserved.
All articles, scripts and material located at the Internet address of http://www.idevelopment.info is the copyright of Jeffrey M. Hunter and is protected under copyright laws of the United States. This document may not be hosted on any other site without my express, prior, written permission. Application to host any of the material elsewhere can be made by contacting me at firstname.lastname@example.org.
I have made every effort and taken great care in making sure that the material included on my web site is technically accurate, but I disclaim any and all responsibility for any loss, damage or destruction of data or any other property which may arise from relying on it. I will in no case be liable for any monetary damages arising from such loss, damage or destruction.