title: Connect to an Access database in Java using NetBeans
body: <p>How do I connect to an Access database in Java?</p>
  
  <p>I have done like this:</p>
  
  <pre><code>package inspection.management.system;
  
  import java.sql.*;
  
  /**
   *
   * @author Fuhans
   */
  
  public class Database 
  {
      public static void DatabaseConnectivity()
      {
          try
          {
              Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  
              String url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + "d:\\program files\\project\\program\\inspection management system\\db1.accdb";
  
              Connection conn = DriverManager.getConnection(url);
  
              System.out.println("Connection Successful");
              InfoBox.ShowMessageBox("Connection Successful!", "Success");
          } 
  
          catch (Exception e) 
          {
              System.err.println("Got an exception!");
              System.err.println(e.getMessage());
  
              InfoBox.ShowMessageBox("Got an Exception!", "Error");
              InfoBox.ShowMessageBox(e.getMessage(), "Error");
          }
      }
  }
  
  if (_textField1.equals("Fuhans") &amp;&amp; _passwordField1.equals("Xavega"))
          {
              Sound.PlaySound(1);
              InfoBox.ShowMessageBox("Successfully Login!", "Success");
              Database.DatabaseConnectivity();
          }
  </code></pre>
  
  <p>When i successfully login, it gave me error on database:</p>
  
  <p><img src="https://i.stack.imgur.com/xYofI.png" alt="enter image description here"></p>
  
  <p>What have i done wrong?</p>