2014-01-23 165 views
0

我寫了下面的簡單代碼:錯誤使用JDBC-ODBC橋驅動程序連接到Oracle

import java.sql.*; 

public class Select_Type1 { 

public static void main(String[] args) throws SQLException{ 

    DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver()); 


    Connection con = DriverManager.getConnection("jdbc:odbc:oradsn","system","password"); 

    Statement stmt = con.createStatement(); 

    ResultSet rs = stmt.executeQuery("select * from EMPLOYEE"); 

    while(rs.next()) 
    { 
     System.out.println("Emplyee_id: "+rs.getInt(1)); 
     System.out.println("Employee_Name: "+rs.getString(2)); 
     System.out.println("Employee_Salary: "+rs.getInt(3)); 
     System.out.println("------------------------------"); 
    } 

} 
} 

下面一行是erronomous: - DriverManager.registerDriver(新sun.jdbc.odbc.JdbcOdbcDriver中( ));

錯誤是: -

- Access restriction: The type JdbcOdbcDriver is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar 

- Access restriction: The constructor JdbcOdbcDriver() is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar 

的任何幫助,將不勝感激。

回答

0

在使用Eclipse作爲我的IDE之前,我有這個錯誤。我不得不做以下修復它。

轉至屬性> Java編譯器>錯誤警告>棄用和受限制的API>禁止引用(訪問規則),然後將其從「錯誤」更改爲「警告」。

+0

做了沒有改變:-( – Vivek

相關問題