为什么在使用SQL Anywhere sajdbc4驱动程序的Wildfly 20中测试连接失败? [英] Why does Test Connection fail in Wildfly 20 Using SQL Anywhere sajdbc4 driver?

查看:101
本文介绍了为什么在使用SQL Anywhere sajdbc4驱动程序的Wildfly 20中测试连接失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前运行过Wildfly 10,并且刚刚升级到Wildfly 20(在Ubuntu 20下)。要使Sybase SQL Anywhere 17 sajdbc4驱动程序正常工作,我在Wildfly 10中的配置将不再起作用。当我测试连接时,它失败。我正在使用相同的配置,并针对完全相同的(SQL Anywhere高可用性)数据库服务器进行测试。

I had Wildfly 10 running previously and have just upgraded to Wildfly 20 (under Ubuntu 20). My configuration from Wildfly 10 no longer works when it comes to getting the Sybase SQL Anywhere 17 sajdbc4 driver working. When I "Test Connection" it fails. I am using the same configuration and testing against the exact same (SQL Anywhere High Availability) database server.

测试连接在以下数据源上触发无效的ODBC句柄;错误:

"Test Connection" on the following Datasource triggers an "Invalid ODBC handle" error:

<datasource jndi-name="java:jboss/datasources/TestDB" pool-name="TestDB" spy="true" tracking="true" enlistment-trace="true">
    <connection-url>jdbc:sqlanywhere:Host=192.168.1.45:19000,192.168.1.45:19001;ServerName=TestDB</connection-url>
    <driver>sajdbc4.jar</driver>
             <security>
                <user-name>...</user-name>
                 <password>...</password>
             </security>
</datasource>

连接无效

原因:java.sql.SQLException:无效部署时的ODBC句柄

Caused by: java.sql.SQLException: Invalid ODBC handle

at deployment.sajdbc4.jar//sap.jdbc4.sqlanywhere.IDriver.makeODBCConnection(Native Method)
at deployment.sajdbc4.jar//sap.jdbc4.sqlanywhere.IDriver.connect(IDriver.java:809)
at org.jboss.ironjacamar.jdbcadapters@1.4.22.Final//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:321)
... 35 more

我如何设置这样:


  1. 我使用控制台部署了sajdbc4.jar,看来工作正常。我没有看到任何错误,并且sajdbc4在控制台中显示为已部署,并且在子系统中也显示为JDBC驱动程序。以下是使用控制台后在standalone.xml中创建的内容:

  1. I used the console to Deploy the sajdbc4.jar and that appears to work fine. I see no errors and sajdbc4 shows up as Deployed in the console and it also shows up as a JDBC Driver in the Subsystems. Here is what was created in standalone.xml after using the console:

deployment name = sajdbc4.jar; runtime-name = sajdbc4.jar
content sha1 = b690ff7a8ba1a3c2e8dd5079138b7970d969c2b9 /
/ deployment>

deployment name="sajdbc4.jar" runtime-name="sajdbc4.jar"> content sha1="b690ff7a8ba1a3c2e8dd5079138b7970d969c2b9"/> /deployment>

(我不得不去掉前导尖括号以显示前几行-即使标记为代码!)
接下来,我必须确保java.library.path和classpath包含sajdbc4.jar及其支持文件的路径,以便Wildfly可以找到它们。为此,我添加了 HACK

(I had to drop the leading angle brackets to get the previous lines to show - even when marked as Code!) Next I had to ensure that the java.library.path and classpath included the path to the sajdbc4.jar and its support files so Wildfly can find them. To do so I added the "HACK" to the following in standalone.conf:

if [ "x$JAVA_OPTS" = "x" ]; then
   JAVA_OPTS="-Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true"
   JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"
   # ADDED FOLLOWING HACK
   JAVA_OPTS="$JAVA_OPTS -Djava.library.path=/opt/wildfly-20.0.1.Final/modules/system/layers/base/com/sybase/main -cp .:/opt/wildfly-20.0.1.Final/modules/system/layers/base/com/sybase/main/sajdbc4.jar"
   echo "Java Properties Next:"
   java -XshowSettings:properties -version
else
   echo "JAVA_OPTS already set in environment; overriding default settings with values: $JAVA_OPTS"
fi

最后,我添加了顶部显示的数据源块。在启动Wildfly之后,TestDB在数据源子系统中显示为数据源,但是当我测试连接时,我得到了无效的ODBC句柄。

Finally, I added the datasource block shown at the top. After starting Wildfly TestDB shows up as a Datasource in the Datasources Subsystem but when I Test Connection I get the "Invalid ODBC handle" error.

我确信驱动程序及其所有支持文件都在正常运行,因为我有一个非常简单的Java测试应用程序,它仅与TestDB建立连接,从表中获取并显示行。请注意,它使用与我在standalone.conf中设置的完全相同的java.library.path和classpath:

I feel confident that the driver and all its support files are "working" because I have a very simple Java test app that just makes a connection to TestDB, fetches from a table and displays the rows. Note that it uses the exact same java.library.path and classpath as I set in standalone.conf:

cd $HOME/Desktop
export LD_LIBRARY_PATH=/opt/wildfly-20.0.1.Final/modules/system/layers/base/com/sybase/main
export CLASSPATH=.:/opt/wildfly-20.0.1.Final/modules/system/layers/base/com/sybase/main/sajdbc4.jar
java sajdbc4DriverTest.java

请注意, server.log没有显示任何错误,并且实际上显示的行如下:

Note that server.log shows no errors and in fact shows lines like:

[org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "sajdbc4.jar" (runtime-name: "sajdbc4.jar")
...
[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-4) WFLYJCA0005: Deploying non-JDBC-compliant driver class sap.jdbc4.sqlanywhere.IDriver (version 4.0)
[org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-3) WFLYJCA0018: Started Driver service with driver-name = sajdbc4.jar
[org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) WFLYJCA0001: Bound data source [java:jboss/datasources/TestDB]
...
[org.jboss.as.server] (Controller Boot Thread) WFLYSRV0010: Deployed "sajdbc4.jar" (runtime-name : "sajdbc4.jar")

请注意,我的连接字符串用于连接到SQL Anywhere High可用性系统(因此有两个URL)。在Wildfly 20中,我看到现在有一​​个新的 HA URL Separator控制台的数据源定义页面中的字段。我尝试将其设置为逗号,然后将测试连接错误更改为无法从URL创建连接:

Note that my connection string is for connecting to a SQL Anywhere High Availability system (hence the two URLS). In Wildfly 20 I see that there is now a new "HA URL Separator" field in the console's Datasource definition page. I tried setting that to a comma and that just changed the Test Connection error to "Unable to create connection from URL":

2020-08-25 11:45:08,378 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (External Management Request Threads -- 1) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031085: Unable to create connection from URL: jdbc:sqlanywhere:Host=192.168.1.45:19000,192.168.1.45:19001;ServerName=TestDB
    at org.jboss.ironjacamar.jdbcadapters@1.4.22.Final//org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getHALocalManagedConnection(LocalManagedConnectionFactory.java:381)

如何我如何获得测试连接?可以上班吗?

How do I get "Test Connection" to work?

提前谢谢您。

推荐答案

问题原来是与我将Wildfly作为服务运行的事实有关,显然我在上面设置java.library.path的努力失败了。我知道错误的原因,但我不知道在作为服务运行时如何设置路径。

The problem turned out to be related to the fact that I was running Wildfly as a service and apparently my efforts above to set the java.library.path is failing. I know the reason for the error but I do not know how to set the path when running as a service.

这篇关于为什么在使用SQL Anywhere sajdbc4驱动程序的Wildfly 20中测试连接失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆