加载 DB2 JDBC 驱动程序时出现 java.lang.UnsatisfiedLinkError

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

java.lang.UnsatisfiedLinkError while loading DB2 JDBC driver

javamacosjdbcdb2

提问by stacker

I try to use jboss-seam with a db2 database, the following error occurs

我尝试将 jboss-seam 与 db2 数据库一起使用,出现以下错误

com.ibm.db2.jcc.a.SqlException: [jcc][10389][12245][3.52.95] while loading the native 
library   db2jcct2, java.lang.UnsatisfiedLinkError: no db2jcct2 in java.library.path  
an error occurred ERRORCODE=-4472, SQLSTATE=null

I tried setting -Djava.library.path=/opt/IBM/db2/V9.5/lib64as well as

我尝试设置-Djava.library.path=/opt/IBM/db2/V9.5/lib64以及

-Djava.library.path=/opt/IBM/db2/V9.5/lib32

Both paths include libdb2jcct2.so

两条路径都包括 libdb2jcct2.so

I also tried to set LD_LIBRARY_PATHwith no effect.

我也试过设置LD_LIBRARY_PATH没有效果。

OS is MacOs

操作系统是 MacOs

EDIT I also tried to use a JDBC4 driver , db2jcc4.jar since jdbc4 drivers shouldn't rely on native libs.

编辑我还尝试使用 JDBC4 驱动程序 db2jcc4.jar,因为 jdbc4 驱动程序不应该依赖于本机库。

采纳答案by Ian Bjorhovde

The IBM Data Server Driver for JDBC and SQLJ includes both Type 2 and Type 4 JDBC drivers. Please check the following:

IBM Data Server Driver for JDBC and SQLJ 包括 Type 2 和 Type 4 JDBC 驱动程序。请检查以下内容:

1) Make sure the driver is in your classpath: db2jcc.jar. Alternatively you can use the JDBC4 driver (db2jcc4.jar), but don't put both in the classpath.

1) 确保驱动程序在您的类路径中:db2jcc.jar。或者,您可以使用 JDBC4 驱动程序 (db2jcc4.jar),但不要将两者都放在类路径中。

2) Make sure that you're specifying the JCC driver (com.ibm.db2.jcc.DB2Driver) in your app configuration.

2) 确保您com.ibm.db2.jcc.DB2Driver在应用程序配置中指定了 JCC 驱动程序 ( )。

3) Use a Type-4 URL like jdbc:db2://server:port/database. If you specify a Type-2 URL like jdbc:db2:databasethen the driver will start looking for native libraries.

3) 使用 Type-4 URL,如jdbc:db2://server:port/database. 如果您指定一个 Type-2 URL,jdbc:db2:database则驱动程序将开始寻找本机库。

回答by dogbane

Have you tried setting DYLD_LIBRARY_PATHtoo? Might be worth a shot.

你也试过设置DYLD_LIBRARY_PATH吗?可能值得一试。

回答by Jayan

From the path, this looks a linux /unix platform. Try running strace/trussto see which directories are getting opened for library.

从路径上看,这看起来是一个 linux /unix 平台。尝试运行strace/truss以查看为库打开了哪些目录。

回答by Fedearne

If the java.library.path(assigned using LD_LIBRARY_PATH env. variable) is wrong you should actually get something like: "failure in load of t2 native library".

如果java.library.path(使用 LD_LIBRARY_PATH 环境变量分配)是错误的,您实际上应该得到类似的信息:“t2 本机库加载失败”。

You can check the java.library.pathto se if the path is included like this.

您可以检查java.library.path是否像这样包含路径。

System.out.println(System.getProperty("java.library.path"));

System.out.println(System.getProperty("java.library.path"));

Could you be missing another jar like db2jcc_license_cu.jar

你会不会错过另一个罐子,比如 db2jcc_license_cu.jar

Maybe post your classpath. You can get it by reading the property java.class.pathfrom the coide (like above).

也许发布您的类路径。您可以通过java.class.path从代码中读取属性来获取它(如上)。

回答by Antonio Varela

Append a "driverType=4;" to your URL.

附加一个“driverType=4;” 到您的网址。

回答by Revoman

I couldn't find a clear example anywhere, so I'm pasting my solution here. What fixed me up was adding a xa-datasource-property of "DriverType" value "4".

我在任何地方都找不到明确的例子,所以我在这里粘贴我的解决方案。修复我的是添加“DriverType”值“4”的 xa-datasource-property。

            <xa-datasource jndi-name="java:/DB2DataSource" pool-name="DB2DataSource" enabled="true" use-ccm="true">
                <xa-datasource-property name="ServerName">
                    my.server.com
                </xa-datasource-property>
                <xa-datasource-property name="DatabaseName">
                    SAMBLEDB
                </xa-datasource-property>
                <xa-datasource-property name="PortNumber">
                    50000
                </xa-datasource-property>
                <xa-datasource-property name="DriverType">
                    4
                </xa-datasource-property>
                <driver>ibmdb2</driver>
                <xa-pool>
                    <is-same-rm-override>false</is-same-rm-override>
                </xa-pool>
                <security>
                    <user-name>username</user-name>
                    <password>supersecret</password>
                </security>
                <recovery>
                    <recover-plugin class-name="org.jboss.jca.core.recovery.ConfigurableRecoveryPlugin"/>
                </recovery>
                <validation>
                    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2ValidConnectionChecker"/>
                    <background-validation>true</background-validation>
                    <stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2StaleConnectionChecker"/>
                    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.db2.DB2ExceptionSorter"/>
                </validation>

            </xa-datasource>