Name jdbc is not bound in this context
2015-09-11 11:09
507 查看
"javax.naming.NameNotFoundException: Name jdbc is not bound in this Context"
这个错误网络上一大堆。大概知道这是应为WEB-INF里的web.xml文件中没有以下配置或者是配置错误:
<resource-ref>
<description>GuestBook</description>
<res-ref-name>jdbc/oracleds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
首先,我们在Tomcat安装文件中找到 conf/context文件并打开, 在这里,我以我用的Oracle数据库
来配置。
<Resource name="jdbc/oracleds" auth="Container" type="javax.sql.DataSource"
maxIdle="30" maxActive="10" maxWait="10000" username="scott" password="113416"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:SNAIL"/>
而在WEB-INF文件下的 web.xml中,我们配置
<resource-ref></resource-ref> 的信息必须与Tomcat中的配置信息一一对应。
例如:
在Tomcat中配置的name="jdbc/oracleds" ,而在 web.xml文件中配置的name="jdbc/oracle"都会引起
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context 错误提示!
认真的看了自己的context.xml和web.xml中的配置,觉得它们正确无误。而错误依然不能消除,那么你看这篇文章就对了,也许它会是你的指路明灯。
你看一下自己的JSP文件,是否有这样一句:
DataSource ds=(DataSource)initContext.lookup("java:/comp/env/jdbc/xinabai");
请将它改为:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/xinbai");
虽然无数本书和帖子告诉你,这两个方法相同。但是,很明显,前一种会在某种情况下产生Name jdbc is not bound in this Context的错误。
具体原因我不清楚,希望知道原因的高人可以告知一二。
这个错误网络上一大堆。大概知道这是应为WEB-INF里的web.xml文件中没有以下配置或者是配置错误:
<resource-ref>
<description>GuestBook</description>
<res-ref-name>jdbc/oracleds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
首先,我们在Tomcat安装文件中找到 conf/context文件并打开, 在这里,我以我用的Oracle数据库
来配置。
<Resource name="jdbc/oracleds" auth="Container" type="javax.sql.DataSource"
maxIdle="30" maxActive="10" maxWait="10000" username="scott" password="113416"
driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@127.0.0.1:1521:SNAIL"/>
而在WEB-INF文件下的 web.xml中,我们配置
<resource-ref></resource-ref> 的信息必须与Tomcat中的配置信息一一对应。
例如:
在Tomcat中配置的name="jdbc/oracleds" ,而在 web.xml文件中配置的name="jdbc/oracle"都会引起
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context 错误提示!
认真的看了自己的context.xml和web.xml中的配置,觉得它们正确无误。而错误依然不能消除,那么你看这篇文章就对了,也许它会是你的指路明灯。
你看一下自己的JSP文件,是否有这样一句:
DataSource ds=(DataSource)initContext.lookup("java:/comp/env/jdbc/xinabai");
请将它改为:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/xinbai");
虽然无数本书和帖子告诉你,这两个方法相同。但是,很明显,前一种会在某种情况下产生Name jdbc is not bound in this Context的错误。
具体原因我不清楚,希望知道原因的高人可以告知一二。
相关文章推荐
- oracle11g中ASM磁盘组的mount
- Android开发之EditText属性详解
- DSOframer 微软官方API的查阅方法
- 好的学习资源链接 ,持续更新....
- [MySQL FAQ]系列 — 为什么InnoDB表要建议用自增列做主键
- js 一句代码string转date
- 将博客搬至CSDN
- viewPager实现图片左右滑动
- 【XSS之Session安全(一)】
- 6、MDT组件安装
- LeetCode_OJ【12】【13】Integer to Roman && Roman to Integer
- 推荐系统中的常用算法
- poj 3984 迷宫问题
- 横竖屏问题总结
- Core animation 学习笔记
- KSDKV1.2 学习
- lnmp配置nginx
- 【译】VisionMobile:开发者经济报告2015 Q3(三):移动平台:剩下两个?
- DSOframer 微软官方API的查阅方法
- 程序猿应该读什么非编程书籍?