从 Java 访问 Visual FoxPro 数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21856285/
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-08-13 11:05:15  来源:igfitidea点击:

Access Visual FoxPro database from Java

javajdbcdbfvisual-foxpro

提问by elysch

I've been trying to access a Visual Fox Pro database from Java for a week now. I'm getting desperate because my project is in a very tied budget and timeframe. (As any other project, I guess, hahaha)

一周以来,我一直在尝试从 Java 访问 Visual Fox Pro 数据库。我越来越绝望,因为我的项目预算和时间安排非常紧张。(和其他项目一样,我猜,哈哈哈)

I have a .dbf, a .cdxand a .fptfiles. I need to be able to look for a record, extract data, and update data. I don't have a VFP licence.

我有一个.dbf,一个.cdx和一个.fpt文件。我需要能够查找记录、提取数据和更新数据。我没有 VFP 许可证。

I hope someone has some pointers or a working example that I can use. If the only way is buying a driver I'll be willing to consider it based on suggestions received.

我希望有人有一些指示或我可以使用的工作示例。如果唯一的方法是购买驱动程序,我愿意根据收到的建议进行考虑。

This is a short description of what I have tried.

这是我尝试过的内容的简短描述。

I found this xBaseJ: java objects to read and write to dBase files. But it doesn't suport CDX index files.

我发现这个xBaseJ: java objects to read and write to dBase files。但它不支持 CDX 索引文件。

Also found this Example to access a dbf. But my tests show this exception: java.sql.SQLException: [Microsoft][Controlador ODBC dBase] La tabla externa no tiene el formato esperado.I guess a translation to english of this error could be something like: java.sql.SQLException: [Microsoft][ODBC dBase Driver] External table is not in the expected format

还发现此示例访问 dbf。但是我的测试显示了这个异常:java.sql.SQLException: [Microsoft][Controlador ODBC dBase] La tabla externa no tiene el formato esperado.我想这个错误的英文翻译可能是这样的:java.sql.SQLException: [Microsoft][ODBC dBase Driver] External table is not in the expected format

Because of that error I think I need a newer driver. In this microsoft pagesay they no longer have an ODBC driver, and everybody should use OLE DB Provider. The problem is I haven't found a way to use it from java.

由于那个错误,我想我需要一个更新的驱动程序。在这个 microsoft page 中说他们不再有 ODBC 驱动程序,每个人都应该使用 OLE DB Provider。问题是我还没有找到从 java 中使用它的方法。

As far as I can tell, there is no wayto do it directly. Found heresomeone talking about a JACOB "thingy", and someone comments about the need to create a C++ or C# "something" to be able to do what I need. I think he is talking about The JACOB Project: A JAva-COM Bridge. But I also don't know what COM calls would actually have to make.

据我所知,没有办法直接做到这一点。在这里发现有人在谈论 JACOB “东西”,有人评论说需要创建 C++ 或 C#“东西”才能做我需要的事情。我认为他在谈论The JACOB Project: A Java-COM Bridge。但我也不知道 COM 调用实际上必须进行什么。

Haven't been able to find a suitable JDBC driver.

一直无法找到合适的 JDBC 驱动程序。

Thank you all.

谢谢你们。

Ely.

伊利。

采纳答案by elysch

I found the way to do it.

我找到了方法。

I ended up using JACOB (from here).

我最终使用了 JACOB(从这里开始)。

  1. Downloaded and installed Visual FoxPro OLE DB driver from http://msdn.microsoft.com/en-US/vfoxpro/bb190232. the direct link is: Microsoft OLE DB Provider for Visual FoxPro 9.0 SP2
  2. Downloaded JACOB version 1.17 binary and source code.
  3. Added jacob.jaras a Java Build Path library
  4. Copied jacob-1.17-x86.dllto the project directory (same place as eclipse's .project file)
  5. Copied jacob-1.17_src\jacob-1.17\samples\com\jacob\samples\adocontents to my src directory and:
    1. Removed the msdirectory
    2. renamed test.javato Main.java
    3. Changed the connection string to: String connectStr = "Provider=vfpoledb;Data Source=C:\\path\\to\\Data\\;Collating Sequence=general;";
    4. Changed the queryStr to match one of the dbf's name
  1. http://msdn.microsoft.com/en-US/vfoxpro/bb​​190232下载并安装 Visual FoxPro OLE DB 驱动程序。直接链接是:Microsoft OLE DB Provider for Visual FoxPro 9.0 SP2
  2. 下载 JACOB 1.17 版二进制和源代码。
  3. 添加jacob.jar为 Java 构建路径库
  4. 复制jacob-1.17-x86.dll到项目目录下(和eclipse的.project文件放在同一个地方)
  5. jacob-1.17_src\jacob-1.17\samples\com\jacob\samples\ado内容复制到我的 src 目录和:
    1. 删除了ms目录
    2. 重命名test.javaMain.java
    3. 将连接字符串更改为: String connectStr = "Provider=vfpoledb;Data Source=C:\\path\\to\\Data\\;Collating Sequence=general;";
    4. 更改 queryStr 以匹配 dbf 的名称之一

Hope this helps someone else.

希望这对其他人有帮助。

回答by Gcc

You may find interesting to use a jdbc driver for foxpro files. I made some quick tests with this one, and it almost looks like you are using a real database in Java.

您可能会发现为 foxpro 文件使用 jdbc 驱动程序很有趣。我用这个进行了一些快速测试,看起来您几乎像是在使用 Java 中的真实数据库。

Regards,

问候,