3

I got a access database, and I'm programming in Java. What can i use to connect my netbeans with my database on localhost?

Only found this code(it uses local db file) for Windows:

try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    String url = "jdbc:odbc:Driver={Microsoft Access Driver " +
        "(*.mdb, *.accdb)};DBQ=C:\\Database\\Northwind 2007.accdb";
    Connection con = DriverManager.getConnection(url);
    System.out.println("Connected!");
    con.close();
} catch (SQLException e) {
    System.out.println("SQL Exception: "+ e.toString());
} catch (ClassNotFoundException cE) {
    System.out.println("Class Not Found Exception: "+cE.toString());
}

Maybe someone know how to modify it for mac environment?

Pondlife
  • 15,283
  • 6
  • 34
  • 51

2 Answers2

2

Take a look at using the UCanAccess JDBC driver available to download. Include all the jar files in the libraries of the project and you should be able to make a connection to your access database without having Access installed. UCanAccess works best with NetBeans.

Gord Thompson
  • 98,607
  • 26
  • 164
  • 342
Thomas
  • 1,051
  • 3
  • 12
  • 24
  • For detailed setup instructions see [Manipulating an Access database from Java without ODBC](http://stackoverflow.com/q/21955256/2144390). – Gord Thompson Mar 22 '15 at 14:21
0

In Access Database Manipulation via JDBC is explained step by step.

Mihai8
  • 2,871
  • 1
  • 18
  • 27
  • String filename = "d:/java/mdbTEST.mdb"; String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="; How can I do this in OS X ? And I have .accdb file not .mdb, there is defference? – Vladimirs Matusevics Jan 17 '13 at 21:36