java 如何在java中查询DBF文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6935600/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 17:57:09  来源:igfitidea点击:

How can I query a DBF file in java

javajdbcdbf

提问by user646539

I have a rather large DBF file, about 40 megs, that I need to be able to query. Right now I am reading the DBF, it's just tabular text, into a h2 database and querying the h2 database. This works, but seems... stupid. I've been looking for a type 4 JDBC driver for DBF, but haven't had any luck. What is the proper way to do this?

我有一个相当大的 DBF 文件,大约 40 兆,我需要能够查询。现在我正在阅读 DBF,它只是表格文本,进入 h2 数据库并查询 h2 数据库。这有效,但似乎......愚蠢。我一直在为 DBF 寻找类型 4 的 JDBC 驱动程序,但没有任何运气。这样做的正确方法是什么?

采纳答案by Olaf

There is a registry of JDBC drivers at http://developers.sun.com/product/jdbc/drivers. You can select your platform, for example dBase for DBF files and look for a driver. For dBase it lists a bunch of drivers and many of them are type 4. I didn't look into details whether any of these drivers are free.

http://developers.sun.com/product/jdbc/drivers 上有 JDBC 驱动程序的注册表。您可以选择您的平台,例如 DBF 文件的 dBase 并查找驱动程序。对于 dBase,它列出了一堆驱动程序,其中许多是类型 4。我没有仔细研究这些驱动程序中是否有任何一个是免费的。

回答by galisha

For such tasks as data exchange for large size - this way for using JDBC bridge seems to me very slowly. Also you can get some runtime errors during data exchange.

对于诸如大尺寸数据交换之类的任务 - 这种使用 JDBC 桥的方式在我看来很慢。此外,您可能会在数据交换期间遇到一些运行时错误。

The best way is using file IO libraries. After some years I issued such pure pure lightweight library and will present you. (Under LGPL)

最好的方法是使用文件 IO 库。几年后我发布了这样一个纯粹的纯轻量级库,并为您呈现。(在 LGPL 下)

You may download it from here

你可以从这里下载

See dbf reading code below. It is very simple.

请参阅下面的 dbf 读取代码。这很简单。

public class Fp26Reader {
  private static void testRead() {
        DbfIterator dbfIterator = DbfEngine.getReader(

        Fp26Reader.class.getResourceAsStream("FP_26_SAMPLE.DBF"), null);

        while (dbfIterator.hasMoreRecords()) {
              DbfRecord dbfRecord = dbfIterator.nextRecord();
              String string = dbfRecord.getString("string");
              float sumFloat = dbfRecord.getFloat("sum_f");
              BigDecimal sumNumeric = dbfRecord.getBigDecimal("sum_n");
              boolean bool = dbfRecord.getBoolean("bool_val");
              Date date = dbfRecord.getDate("date_val");

              System.out.println(string + " " + sumFloat + " " + sumNumeric + " "+ bool + " " + date);
        }
  }

  public static void main(String[] args) {
        Fp26Reader.testRead();
  }

}

}

回答by Ethan Furman

You might also try using Jythonalong with my python dbf module. It allows for searching (brute force and indexed) as well as pythonic usage patterns. Note: I haven't tested with Jython, but am very responsive to help requests.

您也可以尝试将Jython与我的python dbf 模块一起使用。它允许搜索(蛮力和索引)以及 pythonic 使用模式。注意:我没有用 Jython 测试过,但对帮助请求非常敏感。