gpt4 book ai didi

java - Tomcat 中的 JNDI 数据源问题

转载 作者:行者123 更新时间:2023-11-28 21:54:35 25 4
gpt4 key购买 nike

我一直很难使 JNDI 数据源正常工作。按照指示在 http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html我正在使用 Tomcat5.5 连接到 oracle如果我在代码中使用直接 JDBC 连接,我可以正常连接。

这是我的:在我的 META-INF/context.xml 中:

<Resource name="jdbc/mydb" auth="Container"
type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:theserver:1521/mydb"
username="user" password="password" maxActive="20" maxIdle="10"
/>

这是 web.xml 中的内容:

<resource-ref>
<description>please work</description>
<res-ref-name>jdbc/mydb</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>Container</res-auth>
</resource-ref>

代码如下:

   Connection conn = null;
try{
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/mydb");
conn = ds.getConnection();
} catch ....... etc.

我已经尝试了许多不同的配置并开始了一个新的、简单的项目以确保没有额外的 jar 文件发生冲突或类似的事情,但是。

谁能看到任何看起来不对的东西?

当我尝试使用 conn 对象时,服务器上的错误指示 NullPointerException。对不起,它首先提供:org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection)

最佳答案

数据库 url 对我来说似乎损坏了。

尝试:

jdbc:oracle:thin:@theserver:1521/mydb

关于java - Tomcat 中的 JNDI 数据源问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1826181/

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