【问题标题】:How to setup Embedded Firebird and access from Java Application?如何设置嵌入式 Firebird 并从 Java 应用程序访问?
【发布时间】:2017-12-11 07:41:39
【问题描述】:

我在某个目录中有一个 Firebird 数据库文件 test.fdb,我想从 java 应用程序访问数据库。需要访问哪些库文件。

我正在使用 Jaybird JDBC 驱动程序访问嵌入式 Firebird 数据库,但出现错误

线程“主”java.lang.UnsatisfiedLinkError 中的异常:否 java.library.path 中的 jaybird22_x64

我尝试通过System.setProperty("java.library.path", "/home/sk/Desktop/Jaybird/"); 下载并添加 jaybird22_x64.so 文件 还有System.load() and -Djava.library.path

jaybird 文件夹包含文件 jaybird22_x64.so 文件。

我使用的是 Ubuntu 17.04,带有kernel 4.10.0-42-generic

这是我得到的例外。

线程“主”java.lang.UnsatisfiedLinkError 中的异常:否 java.library.path 中的 jaybird22_x64 位于 java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) 在 java.lang.Runtime.loadLibrary0(Runtime.java:870) 在 java.lang.System.loadLibrary(System.java:1122) 在 org.firebirdsql.gds.impl.jni.JniGDSImpl.initJNIBridge(JniGDSImpl.java:64) 在 org.firebirdsql.gds.impl.jni.JniGDSImpl.(JniGDSImpl.java:25) 在 org.firebirdsql.gds.impl.jni.EmbeddedGDSFactoryPlugin.getGDS(EmbeddedGDSFactoryPlugin.java:40) 在 org.firebirdsql.gds.impl.GDSFactory.getGDSForType(GDSFactory.java:275) 在 org.firebirdsql.jca.FBManagedConnectionFactory.getGDS(FBManagedConnectionFactory.java:123) 在 org.firebirdsql.jdbc.AbstractDriver.connect(AbstractDriver.java:130) 在 java.sql.DriverManager.getConnection(DriverManager.java:664) 在 java.sql.DriverManager.getConnection(DriverManager.java:247) 在 test.TestJavaFireBird.main(TestJavaFireBird.java:33)

谁能帮忙,需要哪些库以及如何加载它们?

【问题讨论】:

  • 请指定您使用的确切值。 java.library.path 需要一个包含 .dll(或 .so)的文件夹,而不是文件本身的路径。
  • 无论如何,升级到 Jaybird 3 并关注 lawinegevaar.nl/firebird/jaybird_embedded_example.html 会更简单
  • 我在 java.library.path 中添加了带有完整路径的 jaybird22_x64.so 文件
  • 编辑您的问题并显示确切的值,因为我不知道“完整路径”是指包含 .so 的文件夹的完整路径还是文件的完整路径。你应该使用前者,而不是后者。
  • 您能否指定您使用的是哪个操作系统,如果是 Linux,确切的内核版本?您能否还包括异常的完整堆栈跟踪,而不仅仅是消息?

标签: firebird firebird2.5 jaybird firebird-embedded


【解决方案1】:

Firebird 网站上的二进制文件似乎无法在 Ubuntu 上运行。因此,要使用 Ubuntu 17.04 上嵌入的 Firebird,最简单的方法是使用以下方式安装 Firebird 3.0 服务器:

sudo apt-get install firebird3.0-server

在安装过程中,请确保输入 sysdba 帐户的密码。

这将安装并启动一个完整的 Firebird 3.0 服务器,但另一种方法是自己编译 Firebird。您可以使用

停止和禁用服务器进程
sudo systemctl stop firebird3.0
sudo systemctl disable firebird3.0

接下来,您需要将自己添加到 Firebird 组才能访问 /tmp/firebird 以获取共享锁定文件:

sudo usermod -a -G firebird <your-username>

重新启动以访问该组。这不应该是必要的,但我无法在我的机器上不重新启动的情况下获得该组。

完成这项工作后,您可以尝试通过使用FIREBIRD_LOCK 环境变量指定锁定路径来使其工作,而无需将自己添加到 firebird 组。

接下来使用 Jaybird 3.0 和 JNA 4.4.0 运行您的 Java 应用程序。如果要使用 Jaybird 2.2,则需要自己编译 libjaybird22_x64.so。

如果您确实需要使用 Firebird 2.5,那么您可能需要查看 https://askubuntu.com/questions/945327/how-to-installing-firebird-on-ubuntu-16-04,尽管我不确定这是否仍然适用于 17.04。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多