My Program runs successfully but gives an exception at the runtime. I have followed all the 8 steps to make a JDBC program. The code and image showing the exception are given. I have also created my own DSN(data source name) in the admin settings in my control panel. Anyone who would let me know a solution to this problem. I would be highly grateful to you. Thanks in advance.
This shows the error which I face at the run time
import java.sql.*;
public class JDBC {
public static void main(String[] args)
{
try
{
// TODO Auto-generated method stb
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
String conURL = "jdbc:odbc:PersonDSN" ;
Connection con = DriverManager.getConnection(conURL) ;
Statement st = con.createStatement() ;
String sql = "Select * from Student" ;
ResultSet rs = st.executeQuery(sql) ;
while (rs.next())
{
String sname = rs.getString("SName");
String saddress = rs.getString("SAddress");
String sno = rs.getString("SNumber");
System.out.println(sname + " " + saddress + " " + sno );
}
con.close();
}
catch (Exception a)
{
System.out.print(a);
}
}
}
It looks like a Java version mismatch. You have a compiled class file compiled using Java 12 and are using Java version 8 at runtime.
You can also see answer; https://stackoverflow.com/a/47457251/11226302
I'm guessing if you use jdk12, it should fix the problem.