从linux连接到访问数据库 [英] Connecting to access database from linux

查看:106
本文介绍了从linux连接到访问数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了我的应用程序并在Windows下进行了测试,它在访问数据库文件中写入/读取。

I've created my application and tested it under windows, which writes/reads to/from a access DB file.

但在现实世界中,它将在linux环境中运行,现在我有一个大问题,似乎没有驱动程序可以让linux访问ms acess db,这是我现在建立连接的方式:

But in the real world it will be ran in the linux environment, and I have a big issue now, it appears that there are no drivers for linux to access ms acess db, here is how I make the connection now :

private static Connection getConnection() {
        if (connection == null) {
            try {
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String conStr = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + configuration.getAccessDbFile();
                connection = DriverManager.getConnection(conStr);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return connection;
    }

有没有人遇到类似的东西,有人有什么建议吗?吗?

Has anyone encountered something similar to this, does anybody have a suggestion what could I do ?

这是我在Linux上的例外:

This is the exception I get on the linux :

java.lang.NullPointerException
        at sun.jdbc.odbc.JdbcOdbcDriver.initialize(JdbcOdbcDriver.java:436)
        at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:153)
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:207)


推荐答案

在Linux上运行的应用程序访问MS Access数据库或使用ODBC的情况并不常见。 ODBC是一种Windows技术。 Linux有一些选项,但这不是常见的情况。

It's uncommon for an application running on Linux to access an MS Access database or use ODBC. ODBC is a windows technology. There are some options for linux, but it's not a common scenario.

正如您所发现的,Linux机器上没有Access ODBC驱动程序,所以JDBC- ODBC桥接失败。您可能能够安装合适的ODBC驱动程序,但我不知道任何免费或开源的驱动程序。 linux的defacto ODBC选项是:

As you've discovered, there are no Access ODBC drivers on your linux machine, so the JDBC-ODBC bridge fails. You might be able to install a suitable ODBC driver, but I don't know of any that are free or open-source. The defacto ODBC option for linux is:

  • http://www.unixodbc.org/

基于UnixODBC的Access的商业驱动程序:

A commercial driver for Access based on UnixODBC:

  • http://www.easysoft.com/products/data_access/index.html

可以连接到Access数据库的类型4 JDBC驱动程序:

A type 4 JDBC driver that can supposedly connect to Access databases:

  • http://www.hxtt.com/access.html

我没有任何相关的个人经验。 4型JDBC驱动程序是理想的,但我会怀疑它的效果和广告一样完美。

I don't have personal experience with any of these. The type 4 JDBC driver would be ideal, but I'd be skeptical that it works as perfectly as advertised.

(我相信你有理由,但是如果您打算部署到Linux机器,我不得不想知道为什么要使用Access数据库。我相信让Java应用程序使用Access数据库的唯一理由是,它是一个现有的Access应用程序,其自定义编程用于超出Java应用程序。否则,有许多更好的选择。另外考虑如果你使用Access的主要原因是你可以使用Access作为表单和报告的用户友好的GUI工具,你仍然可以存储数据限制较少的数据库(Derby,SQLLite,MySQL,PostgreSQL,MS SQL Server等),然后通过ODBC从Access连接到数据库。)这将允许您在Linux上部署Java应用程序,在最有意义的地方部署数据库,以及仍然使用Access从Windows连接到数据库。我已经多次这样做了。)

这篇关于从linux连接到访问数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆