-1

I'm getting run time error

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

when I tried to login using the code given. Below is the code. I'm using Java JRE 7 to compile it. Can anyone please let me know what's the problem? I've omitted most of the code. Link to full code : https://codeshare.io/5gNyZw .

try
{
    String database="StegoKeys.mdb";
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + database + ";PWD=cegospdv";
    Connection con=DriverManager.getConnection(url);

    String sql="select * from keys";
    PreparedStatement ps=con.prepareStatement(sql);

    ResultSet rs=ps.executeQuery();
    while(rs.next())
    {
       if(txtKey.getText().equals(rs.getString("key")))
           {
            id=rs.getString("uname");
            if(txtname.getText().equals(id))
            {
                int stat=Integer.parseInt(rs.getString("status"));
                flag=1;
                if(stat==1)
                {
                      button1.setEnabled(true);
                      button2.setEnabled(true);
                      btnadminset.setVisible(true);
                      txtKey.setEnabled(false);
                      btnLogin.setEnabled(false);
                }                   
                else
                {
                      button1.setEnabled(true);
                      txtname.setEnabled(false);
                      txtKey.setEnabled(false);
                      btnLogin.setEnabled(false);
                }
            }
            //System.out.println(id+" in MainStego");
            con.close();
            break;
        }               
    }
    if(flag==0)
    {
        JOptionPane.showMessageDialog(this,"Invalid User & Key");
    }
   }
 catch(Exception ex)
 {
    JOptionPane.showMessageDialog(this,"Run Time Error");
Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
  • *"I've omitted most of the code."* - You've also omitted the error. Perhaps you could share that information? – David Apr 29 '18 at 11:30
  • Nah, whenever i try to run this program, i'm getting Run Time Error as mentioned in the catch block. Here is the full link to code : https://codeshare.io/5gNyZw. Line No 210 is responsible for the error, but i'm not sure why the try block is not working. – Ashish Kumar Apr 29 '18 at 11:32
  • *"Nah"* - So... You just *don't want* to tell us the error message, or you *don't want* to even look at it yourself? Pro tip: When you want to fix an error, *actually looking at the error message* is usually the first step. In your case the contents of the `ex` variable. – David Apr 29 '18 at 11:34
  • Error : java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified – Ashish Kumar Apr 29 '18 at 11:49
  • @AshishKumar - Does `System.getProperty("sun.arch.data.model")` return "64"? – Gord Thompson Apr 29 '18 at 12:40

1 Answers1

0

The most likely cause of your error is that you are running your Java code under a 64-bit JVM (Java Virtual Machine). Driver={Microsoft Access Driver (*.mdb)} is only available to 32-bit applications.

Your options are:

  1. Download and install the 32-bit JRE (Java Runtime Environment) for Java 7 and use that to run your code.
  2. Download and install the 64-bit version of the Access Database Engine and then use Driver={Microsoft Access Driver (*.mdb, *.accdb)} in your code running under the 64-bit JVM.
  3. Use UCanAccess instead of the JDBC-ODBC Bridge and the Access ODBC driver
Gord Thompson
  • 98,607
  • 26
  • 164
  • 342