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).

When designing code to run outside the database, the application developer will choose a JDBC connection as follows:

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.

Demonstrate using the Thin Driver

  1. Open the file OracleConnection.java and change the username and password.

  2. Compile the source code:
      javac OracleConnection.java TestThinConnection.java
  3. Run the example
      java TestThinConnection
Demonstrate using the kprb Driver

  1. Open the files OracleConnection.java, RunJServer.sql, LoadJServer.sh and CallSpecJServer.sql and change the username and password.

  2. Load the OracleConnection.java and TestJServerConnection.java source code into the Oracle database using the UNIX shell script
  3. Create the CALL SPEC packge: JServer_mgr
      SQL> @CallSpecJServer
  4. Run the example
      SQL> @RunJServer
Example Code Repository

Helper Class Source Code:
OracleConnection.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.java is a small Java program that uses the helper class OracleConnection to make its connection to the database.
Example output of TestThinConnection.
Testing the JServer Driver:
TestJServerConnection.java is a small Java program that uses the helper class OracleConnection to make its connection to the database.
LoadJServer.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.sql is used to create the "Call Specs" needed for the example JServer_mgr Testing Application.
The RunJServer.sql script can be used to run the JServer_mgr.show_user() method.
Example 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 jhunter@idevelopment.info.

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.

Last modified on
Thursday, 18-Nov-2010 18:15:52 EST
Page Count: 45163