user1999758
user1999758

Reputation: 94

Getting an error when try to connect to Oracle java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver

i am trying connect to Oracle Database through following program. but throws an error java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver "

only SQL developer client is installed on my machine whereas Actual data base is store on Server. Please help on resolving the issue

package test;

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;

public class DBConnection {

    public static void main(String[] argv) {

        System.out.println("-------- Oracle JDBC Connection Testing ------");

        try {

            Class.forName("oracle.jdbc.driver.OracleDriver");

        } catch (ClassNotFoundException e) {

            System.out.println("Where is your Oracle JDBC Driver?");
            e.printStackTrace();
            return;

        }

        System.out.println("Oracle JDBC Driver Registered!");

        Connection connection = null;


    enter code here
        try {

            connection = DriverManager.getConnection(
                    "jdbc:oracle:thin:@hostname:5800:SID", "user","password");

        } catch (SQLException e) {

            System.out.println("Connection Failed! Check output console");
            e.printStackTrace();
            return;

        }

        if (connection != null) {
            System.out.println("You made it, take control your database now!");
        } else {
            System.out.println("Failed to make connection!");
        }
    }

}

Upvotes: 1

Views: 1979

Answers (1)

shazin
shazin

Reputation: 21923

Add your Oracle JDBC Driver jar to the classpath

Can download the driver for your Oracle Database Version from here

Upvotes: 1

Related Questions