Anandv
Anandv

Reputation: 107

Unable to connect with oracle 11g via java

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

Upvotes: 0

Views: 745

Answers (2)

Salah
Salah

Reputation: 8657

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.

Upvotes: 2

seph
seph

Reputation: 118

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

Upvotes: 1

Related Questions