I have just started getting familiar with JAVA JDBC. When I am trying to compile the below code in Eclipse,I am getting an error. I hope I will get some help here. Error is mentioned below the code.
import java.sql.*;
import sun.jdbc.odbc.*;
public class JdbcDriver {
public static void main(String args[]) throws SQLException
{
JdbcOdbcDriver d = new JdbcOdbcDriver();
System.out.println("Drivers are loaded");
//register driver
DriverManager.registerDriver(d);
System.out.println("Driver is registered");
//Establish connection with Oracle DB
Connection con= DriverManager.getConnection("jdbc:odbc:oradsn","Scott", "Tiger");
if(con!=null)
System.out.println("Connection is Established");
else
System.out.println("Connection is Fail");
//create statement object for sending query to DB
Statement st= con.createStatement();
System.out.println("Statement object is created");
//use statement object to execute the query
String nss= "INSERT INTO DEPT VALUES(90,"IT","KPHB")";
int i=st.executeUpdate(nss);
System.out.println(i+"rec are inserted");
//close the connection
con.close();
st.close();
}
}
Errors in console:
**Exception in thread "main" java.lang.Error: Unresolved compilation problems: 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 Access restriction: The type JdbcOdbcDriver is not accessible due to restriction on required library C:\Program Files\Java\jre7\lib\rt.jar Syntax error on tokens, delete these tokens at JdbcDriver.main(JdbcDriver.java:8)****
Can anyone help me? Thank you in advance.