开发者

Using Java to retrieve data from a Microsoft Access database [duplicate]

开发者 https://www.devze.com 2023-04-07 14:11 出处:网络
This question already has an answ开发者_高级运维er here: Manipulating an Access database from Java without ODBC
This question already has an answ开发者_高级运维er here: Manipulating an Access database from Java without ODBC (1 answer) Closed 6 years ago.

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.


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 
    }
}


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号