无法通过java连接到oracle 11g 我试图通过java与Oracle 11g建立连接,并添加了ojdbc14和ojdbc6,但在编译时仍然出现此错误。请帮助。 我的代码是

无法通过java连接到oracle 11g 我试图通过java与Oracle 11g建立连接,并添加了ojdbc14和ojdbc6,但在编译时仍然出现此错误。请帮助。 我的代码是,java,oracle,jdbc,Java,Oracle,Jdbc,打开连接 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",

打开连接

           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){
处理Class.forName的错误

          e.printStackTrace();
       }finally{

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

您需要将JDBC驱动程序添加到类路径中

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

下载Oracle,然后将其添加到类路径中。

您的ojdbc$version.jar似乎不在类路径中。

@Anandv-异常清楚地表明您没有这样做。或者至少,您没有将它添加到应用程序实际使用的类路径中。
java.lang.ClassNotFoundException: com.oracle.jdbc.Driver // this error shows that your application is missing oracle jdbc driver.
java.lang.ClassNotFoundException: com.oracle.jdbc.Driver // this error shows that your application is missing oracle jdbc driver.