我写了以下简单的代码:
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
非常感谢任何帮助。
答案 0 :(得分:0)
在使用Eclipse作为我的IDE之前,我遇到了这个错误。我不得不做以下事情来解决它。
转到“属性”> Java编译器>错误警告>弃用和受限制的API>禁止引用(访问规则),然后我将其从Error更改为Warning。