title: What's the right way in Java to connect to a Microsoft Access 2007 database?
body: <p>I'm trying to create a simple connection using the jdbc-odbc bridge:</p>
  
  <pre><code>public static Connection  getConnection() {
      Connection con =null;
      try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          String conStr = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" +
              "c:\\myfolder\\accesdbfile.accdb";
          con = DriverManager.getConnection(conStr);
      } catch(Exception e) {
          e.printStackTrace();}
      return con;
  }
  </code></pre>
  
  <p>But then I get this exception:</p>
  
  <pre><code>java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process 0xa4 Thread 0xec0 DBC 0x2f8574c                                                              Jet'.
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>Update 24/Mar/2009: Now it's working. Created a User Data Source, and for some reason the exception went away.</p>
  
  <p>As a general question, What would be the best way to handle database connections in Java?</p>