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.

1

3 Answers 3

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 
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

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.
This answer is outdated because the JDBC-ODBC Bridge has been removed from Java 8. For an alternative, see this question.
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

1 Comment

thanks for the link. I will give it a read.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.