使用jdbc-odbc Bridge驱动程序连接到Oracle时出错

时间:2014-01-23 12:54:03

标签: java jdbc

我写了以下简单的代码:

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

}
}

以下行是错误的: -     DriverManager.registerDriver(new 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

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

在使用Eclipse作为我的IDE之前,我遇到了这个错误。我不得不做以下事情来解决它。

转到“属性”> Java编译器>错误警告>弃用和受限制的API>禁止引用(访问规则),然后我将其从Error更改为Warning。