0

我有一个独立的应用程序需要通过数据源连接到 Sybase 数据库,我正在尝试使用 getConnection() 进行连接并从托管在 WAS 6.1 中的这个 Sybase 数据源获取连接,遗憾的是我收到了错误 JZ004 -> Sybase(R) jConnect for JDBC(TM) 程序员参考:SQL 异常和警告消息

JZ004 错误消息是:
DriverManager.getConnection(..., Properties) 中缺少用户名属性 操作:提供所需的用户属性。

如您所见,这不是连接问题(因此我们可以丢弃 JNDI 或查找问题),而是配置问题。对于我在 WAS 6.1 中的 Sybase 数据源,我已经设置了正确的身份验证别名(组件管理的身份验证别名),并且我知道凭据没问题,“测试连接”对于这个数据源是成功的。有人有类似的问题,是因为身份验证别名-> http://forum.springsource.org/showthread.php?t=39915

接下来,我尝试调用 getConnection() 但现在我提供了 getConnection(user, password) 之类的凭据......这次它成功了!!!所以我怀疑 WAS 6.1 不知何故没有选择或获取我在数据源中设置的身份验证信息,如前所述。

如果您认为 getConnection(user, password) 对于我的情况应该没问题,那么情况并非如此,因为我需要将凭据保存在服务器中,独立应用程序只需要知道 JNDI 信息即可查找数据源。

如果遇到类似的问题,请告诉我,或者你会建议我做什么。

谢谢。

4

2 回答 2

0

为了使用配置的资源,您需要查找它而不是直接使用 DriverManager:

new InitialContext().lookup("myDS");
于 2010-04-18T15:56:28.423 回答
0

In another thread -> Call to DataSource.getConnection not returning the expected connection, I got an answer that also solved this issue, basically the answer is that an authentication alias won't work for external clients according to the J2C documentation. The workaround is to provide the user and password as custom properties instead of being provided as an authentication alias.

于 2010-04-23T02:29:51.467 回答