1

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!");
        }
    }

}

1 Answer 1

1

Add your Oracle JDBC Driver jar to the classpath

Can download the driver for your Oracle Database Version from here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.