0

I was trying to make connection with Oracle 11g via java and i have added ojdbc14 and ojdbc6 but still i am getting this error while compiling.Please help.

        java.lang.ClassNotFoundException: com.oracle.jdbc.Driver
         Goodbye!
            at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown 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.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at JDBC.main(JDBC.java:21)

And My Code is

        import java.sql.*;


        public class JDBC {

         public static void main(String[] args) {
           Connection conn = null;
            Statement stmt = null;

Open a connection

           try{
        Class.forName("com.oracle.jdbc.Driver");


          System.out.println("Connecting to database...");

           conn = DriverManager.getConnection
          ("jdbc:oracle:thin:@172.16.209.169:1521:heritage", "USERNAME", "PASSWORD");

     }catch(SQLException se){

          se.printStackTrace();
       }catch(Exception e){

Handle errors for Class.forName

          e.printStackTrace();
       }finally{

         try{
             if(conn!=null)
                conn.close();
          }catch(SQLException se){
             se.printStackTrace();
          }
       }
       System.out.println("Goodbye!");
    }

2 Answers 2

2

You need to add JDBC driver to your class path.

java.lang.ClassNotFoundException: com.oracle.jdbc.Driver // this error shows that your application is missing oracle jdbc driver.

Download Oracle jdbc driver, then add it to your class path.

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

1 Comment

@Anandv - The exception clearly indicates that you have not done that. Or at least, you have not added it to the classpath that the application is actually using.
1

Your ojdbc$version.jar seems not to be in the classpath.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.