【发布时间】:2011-12-20 12:57:17
【问题描述】:
我正在尝试通过 Tomcat JNDI 资源建立与我的数据库的连接。我今天看了很多文章,似乎找不到答案。
在我的 server.xml 我有:
<GlobalNamingResources>
<Resource name="jdbc/MyDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="tomcat" password="...."
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3333/tomcat?autoReconnect=true"/>
.....
</GlobalNamingResources>
在我的网络服务中,我尝试通过以下方式访问资源:
InitialContext ctx = new InitialContext();
DataSource data = (DataSource)ctx.lookup("java:comp/env/jdbc/MyDB");
Connection conn = data.getConnection();
当我运行代码时,我得到了这个异常:
Nov 2, 2011 1:06:20 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
...
我的网络应用程序库和 tomcat 库中都有最新的 mysql-connector-java-5.1.18-bin.jar。
你能帮我解决这个问题吗?
【问题讨论】:
-
您找到解决方案了吗?我也在寻找一种方法来做到这一点
-
我也在寻找解决方案
-
添加了答案
标签: mysql jakarta-ee tomcat jndi jax-rs