找不到ODBC驱动程序管理器..用Java连接MS Access?

时间:2014-07-17 22:02:49

标签: java database odbc

运行程序时,此问题出现在我身上 http://i.stack.imgur.com/3uCDX.png

来自Control Panel > Administrative Tools > ODBC Data Source (64-bit) User DSN not contain MSAccess

无法添加Access驱动程序.. http://im74.gulfup.com/aUnu7p.png

请问如何解决这个问题,谢谢你......

这是我的代码。

public class Main 
{
    private static final String MyDataBase = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBO=C:\\Users\\samer\\workspace\\DS2\\DB\\DS2.mdb;";      
    private static Connection conn = null;
    private static Statement stat = null ;

    public Main() 
    {
        try 
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            conn = DriverManager.getConnection(MyDataBase);
            stat = conn.createStatement();
            String sql = "insert into Employee values (1001,'10011001')";
            stat.execute(sql);    
            JOptionPane.showMessageDialog(null , "correct insert");
        } 
        catch (SQLException e1) 
        {
            e1.printStackTrace();
            JOptionPane.showMessageDialog(null , "Sorry1 ,  Try again !!");
        } catch (ClassNotFoundException e2) 
        {
            e2.printStackTrace();
            JOptionPane.showMessageDialog(null , "Sorry2 ,  Try again !!");
        }
    }

    public static void main(String[] args) 
    {
        new Main();
    }
}

1 个答案:

答案 0 :(得分:1)

我相信驱动程序正在消失(它不在Java 8中)。

我一直在Java中使用名为UCanAccess的JDBC解决方案,它对我来说效果很好。

http://ucanaccess.sourceforge.net/site.html