-1

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

enter image description here

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);

        }
    }
}
Shekhar Rai
  • 2,008
  • 2
  • 22
  • 25
Ali Akbar
  • 23
  • 1
  • 8
  • 1
    What do you think the exception message means? – Thorbjørn Ravn Andersen Dec 07 '19 at 08:13
  • 2
    Don't post screenshots of errors, include the error as text in your question. – Erwin Bolwidt Dec 07 '19 at 08:36
  • Please don't post pictures of code, or pictures of error messages, or pictures of logs, or generally pictures of any kind of text. Text in pictures cannot be searched, text in pictures cannot be copypasted into an IDE, text in pictures cannot be copypasted into a web search engine, and text in pictures cannot be read by blind or otherwise visually impaired people. Just copy the text and paste it into your question as text. If you are unsure how to format it properly, don't worry, we can help with that. – Max Vollmer Dec 07 '19 at 13:07
  • Thank you for letting me know about the problems. I would take care of them – Ali Akbar Dec 10 '19 at 17:53

1 Answers1

0

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.

Shivam Puri
  • 1,578
  • 12
  • 25