gpt4 book ai didi

java - 无法加载 Firebird 客户端库 : Embedded database with Jaybird

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:28:51 26 4
gpt4 key购买 nike

我一直在开发一个连接到 Firebird 数据库并监听事件的程序。我试图让它与嵌入式数据库一起工作。

EventManager em = new FBEventManager(GDSType.getType("EMBEDDED"));
em.setHost("localhost");
em.setDatabase("C:\\test.fdb");
em.connect();
Exception in thread "main" java.lang.RuntimeException: Failed to initialize Jaybird native library. This is most likely due to a failure to load the firebird client library.
at org.firebirdsql.gds.impl.jni.JniGDSImpl.attemptToLoadAClientLibraryFromList(JniGDSImpl.java:106)
at org.firebirdsql.gds.impl.jni.EmbeddedGDSImpl.<init>(EmbeddedGDSImpl.java:31)
at org.firebirdsql.gds.impl.jni.EmbeddedGDSImpl.<init>(EmbeddedGDSImpl.java:21)
at org.firebirdsql.gds.impl.jni.EmbeddedGDSFactoryPlugin.getGDS(EmbeddedGDSFactoryPlugin.java:40)
at org.firebirdsql.gds.impl.GDSFactory.getGDSForType(GDSFactory.java:220)
at org.firebirdsql.event.FBEventManager.<init>(FBEventManager.java:91)
at eventhandler.FirebirdEventMaster.<init>(FirebirdEventMaster.java:42)
at eventhandler.FirebirdEventMaster.getInstance(FirebirdEventMaster.java:33)
at eventhandler.Driver.main(Driver.java:13)

经过多次谷歌搜索,我试过...

“虚拟机选项”: -Djava.library.path="C:\Users\jrile\Downloads\Jaybird-2.2.3JDK_1.6"

“FIREBIRD”和“PATH”系统变量:“C:\Users\jrile\Downloads\Firebird-2.5.2.26540-0_x64_embed”

使用 Windows 64 位和 Firebird Embedded 64 位。任何帮助将不胜感激

最佳答案

我创建了一个非常简单的程序来连接到嵌入式 Firebird:

package pkg;

import java.sql.*;

public class MainClass {

public static void main(String[] args) throws SQLException {
try (Connection con = DriverManager
.getConnection("jdbc:firebirdsql:embedded:D:/data/db/testdatabase.fdb", "sysdba", "")) {
try (
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM RDB$DATABASE");
) {
while (rs.next()) {
System.out.println(rs.getString(2));
}
}
}
}
}

这是在布局中:

src
+--pkg
+--MainClass.java

我打开命令提示符,然后转到 src 文件夹并编译:

javac -cp . pkg\MainClass.java

我更新了路径以包含 64 位 Firebird 嵌入式文件

...\src>SET PATH=%PATH%;D:\Development\project\JaybirdEclipse\native_test_files_64bit

..\src>java -cp .;D:\Development\libs\Jaybird-2.2.3JDK_1.7\jaybird-full-2.2.3.jar
-Djava.library.path=D:\Development\libs\Jaybird-2.2.3JDK_1.7
pkg.MainClass
160

其中 160 是我数据库中表 RDB$DATABASE 中列 RDB$RELATION_ID 的值。

现在,如果我改为使用 32 位 JRE 执行,我会得到与您遇到的完全相同的错误:

...\src>"C:\Program Files (x86)\java\jre7\bin\java" 
-cp .;D:\Development\libs\Jaybird-2.2.3JDK_1.7\jaybird-full-2.2.3.jar
-Djava.library.path=D:\Development\libs\Jaybird-2.2.3JDK_1.7
pkg.MainClass
Exception in thread "main" java.lang.RuntimeException: Failed to initialize
Jaybird native library. This is most likely due to a failure to load the firebird
client library.

请注意,当您没有将 Firebird 嵌入到您的 PATH(或您的 Java 应用程序的根文件夹中)时,您会遇到同样的错误。我的猜测是您正在尝试使用 32 位 Java 而不是 64 位版本运行它。

关于java - 无法加载 Firebird 客户端库 : Embedded database with Jaybird,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17449967/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com