gpt4 book ai didi

java - JNDI - WAS 7 中的 JDBC 资源查找失败

转载 作者:行者123 更新时间:2023-11-30 09:07:59 25 4
gpt4 key购买 nike

我的代码无法使用 JNDI 查找 JDBC 资源。我收到以下异常:

[根异常是 javax.naming.NameNotFoundException:上下文:ppp-14415Node01Cell/nodes/ppp-14415Node01/servers/server1,名称:jdbc/admincob:未找到名称 admincob 中的第一个组件。 [根异常(exception)是 org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]]

我在 SO 上遵循了这两个解决方案,但仍然无法正常工作

Websphere 6.1 to 7 how to update ibm-web-bnd.xmi to ibm-web-bnd.xml

How do I connect to a Websphere Datasource with a given JNDI name?

这是我的 ibm-web-bnd.xml

    <virtual-host name="default_host" />
<resource-ref name="jdbc/dbcob" binding-name="jdbc/admincob" />

和 web.xml 的一部分

    <resource-ref>
<description>
Datasource connection to db</description>
<res-ref-name>jdbc/dbcob</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

绑定(bind)截图如下: binding description

查找代码:

       Context initialContext = new InitialContext();

DataSource datasource = (DataSource) initialContext
.lookup("java:comp/env/jdbc/dbcob");
if (datasource != null) {
result = datasource.getConnection();
System.out.println("Data connection retrieved");
result.close();
} else {
System.err.println("Failed to lookup datasource.");
}

我不确定我错过了什么。请帮忙。

enter image description here enter image description here

最佳答案

发生这种情况是因为您的数据源是在 Cell:/Node:14415Node02/Server:server1 范围内定义的(根据数据源定义的屏幕截图),而您的应用程序配置为运行在 Cell:/Node:14415Node01/Server:server1 上(根据您附加的异常文本)。

换句话说,您正在节点 A 上的服务器 server1 上运行您的应用程序,而数据源定义的范围仅限于节点 B。此数据源只能被范围内的服务器看到在节点 B 内。

关于java - JNDI - WAS 7 中的 JDBC 资源查找失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23812642/

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