Connectivity Jdbc & oracle database Troubleshooting java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

This blog will allow DBA’s to troubleshoot connectivity between Jdbc & oracle database

It will also help to tackle common Java connectivity errors like below in windows environment where tracing/debugging is very difficult  

java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at$ Source)
at Method)
at Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at bpos.Db.Conectar(
at bpos.Process.main(

Generally we rely on ping, telnet, tnsping & sqlplus for connectivity checks between oracle client & database
ping <HostName/IP>
Telnet <Hostname/IP>  <Listener_Port>
sqlplus aradmin@REMCORP_NEW/<password>

And we are happy to say “No issues at DB end, able to connect to database from sqlplus please check from you Java Application!”

Now going one step ahead lets help the Java developers to resolve this issue by getting our test script in place on client machine

Java Script: Save it as

import java.sql.*;
import java.lang.*;
public class JdbcCon
    public static void main(String args[]) {
        //Connection con = null;
        String url = "jdbc:oracle:thin:@";
        //String db = "css";
        String driver = "oracle.jdbc.driver.OracleDriver";
        String user = "css";
        String pass = "css1234";
        try {
            Connection con = DriverManager.getConnection(url, user, pass);
            System.out.println("Connection is created...");
            System.out.println("Connection is closed...");
        } catch (Exception e) {

What script does? It will make a connection to DB using Oracle Jdbc driver oracle.jdbc.driver.OracleDriver & disconnect. Appropriate database DB IP, Port, DB/Service name user & password (Highlighted) should be provided in script

On oracle client machine save above java code file as in a location e.g. D:\
Java file Location = D:\

For 10g & Above
CLASSPATH= D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar
For 9i & below
CLASSPATH= D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar

Set & Verify variable at session level for testing as below

set CLASSPATH=D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar

Complie code:
javac –verbose
Execute Code:
java JdbcCon

D:> javac –verbose
D:> java Jdbc
Connection is created...
Connection is closed...

Note: During multiple round of testing if you do not change code, then compilation step is not necessary in the same session, before re-compiling delete the .class file generated in script location location 

You can verify your listener.log at DB server to check if connection establishes w.r.t. IP/Hostname of the application Machine
In Windows, You can set environment variables across the sessions as below 

Start>Computer (Right Click)>Properties>Advance System Setting>Environment Variables > New/Edit

Any In-appropriate setting will lead to error
java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

Optionally, You can set Jdk lib path as well in environment variable separated by “;” make sure at the end its “;.;”
Also, Make Sure JAVA_HOME of application is set appropriately in environment variables


  1. This page is very useful. Thank you

  2. Very interessant and explain are clear but when executing after good compiling result is giving an error : impossible to found or load the main class ?