2

I'm looking to create a Java program that retrieves data from Microsoft Access database (and possible store onto it).

Is this possible? If yes, is it complicated to do? Also are there any examples of Java programs (or code) that does this?

Thanks.

HansUp
  • 92,185
  • 11
  • 67
  • 122
Mr Teeth
  • 1,109
  • 5
  • 16
  • 21
  • 1
    The JDBC-ODBC bridge is no more, today one can refer to http://stackoverflow.com/questions/21955256/manipulating-an-access-database-from-java-without-odbc – Tunaki Jul 25 '16 at 11:54

3 Answers3

4

Yes, it's perfectly possible. Java's JDBC-ODBC bridge is your best friend for this.

First, you need to configure an ODBC access to your MSAccess database.

Then, you need this simple piece of code:

import java.sql.*;

public class AccessManager {

    private Connection con;
    private Statement st;
    private static final String url="jdbc:odbc:my_access_odbc_dsn";
    private static final String className="sun.jdbc.odbc.JdbcOdbcDriver";
    private static final String user="";
    private static final String pass="";

    AccessManager()throws Exception {
        Class.forName(className);
        con = DriverManager.getConnection(url, user, pass);
        st = con.createStatement(); 
        // you can do select, insert, update, delete from 
    }
}
Pablo Santa Cruz
  • 162,219
  • 30
  • 224
  • 277
  • thanks a lot for this reply. I will look into "Java's JDBC-ODBC bridge". I've never heard of it before. The code looks like something I can work with. Again, thank you. – Mr Teeth Sep 25 '11 at 01:19
  • This answer is outdated because the JDBC-ODBC Bridge has been removed from Java 8. For an alternative, see [this question](http://stackoverflow.com/q/21955256/2144390). – Gord Thompson Jul 25 '16 at 14:20
1

yes, this should be possible via JDBC : so it is as easy as using any other DBMS in java.

take a look at this document

thomas
  • 5,549
  • 2
  • 22
  • 34
0

While this is perfectly possible using the JDBC-ODBC bridge. The configuration isn't easy to set up, especially if you have an architecture mismatch. Ensure you are using the same architecture for both the JDK, Driver, IDE, OS to prevent ridiculous bugs. If you're using a 64 bit OS ensure tool is also 64 bit. Same applies for 32 bits.

Tut Tut2

Mob
  • 10,435
  • 6
  • 37
  • 57