title: How to connect MS Access Database using Java program?
body: <p>I want to write a program to retrieve data from MS Access database. I wrote program as bellow:</p>
  
  <pre><code>package db;
  
  import java.sql.*;
  
  public class MSaccess_archive {
      public static void main(String[] args) {
  
          try {
  
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  
              String accessFileName = "E:/L4_project/sample/db/Database";
  
              String connURL="jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ="+accessFileName+".accdb;";
  
              Connection con = DriverManager.getConnection(connURL, "","");
  
              Statement stmt = con.createStatement();
  
              stmt.execute("select * from student"); // execute query in table student
  
              ResultSet rs = stmt.getResultSet(); // get any Result that came from our query
  
              if (rs != null)
               while ( rs.next() ){
  
                  System.out.println("Name: " + rs.getString("Name") + " ID: "+rs.getString("ID"));
                  }
  
                  stmt.close();
                  con.close();
              }
              catch (Exception err) {
                  System.out.println("ERROR: " + err);
              }
      }
  
  }
  </code></pre>
  
  <p>But I got Exception as below:</p>
  
  <blockquote>
    <p>ERROR: java.sql.SQLException: [Microsoft][ODBC Microsoft Access
    Driver] Could not find file '(unknown)'.</p>
  </blockquote>
  
  <p>When I used a <code>.mdb</code> file the above program works correctly but if I use a <code>.accdb</code> file it gives the above exception.</p>
  
  <p>Any ideas why?</p>