首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context解决方法!

2014-01-26 
Tomcat 5.5 + MySQL 配置的数据库连接池出问题了 是按照网上写的在%TOMCAT_HOME%\conf\Catalina\localhost

Tomcat 5.5 + MySQL 配置的数据库连接池出问题了
是按照网上写的在%TOMCAT_HOME%\conf\Catalina\localhost下创建同项目名称的xml文件
不过还是出现这个错误信息
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
实验室的机器让我稀里糊涂配成功了
寝室的就是不行
xml文件我复制机房的过来也不成
以下是XML文件内容

<Context path= "/nbcs " docBase= "C:\Tomcat\webapps\nbcs " reloadable= "true " crossContext= "true " debug= "0 " >

<Resource name= "jdbc/yiyang " auth= "Container " type= "javax.sql.DataSource " maxActive= "100 " maxIdle= "30 " maxWait= "10000 " username= "yiyang " password= "123456 " driverClassName= "com.mysql.jdbc.Driver " url= "jdbc:mysql://localhost/yiyang?useUnicode=true&amp;characterEncoding=GBK "/>

</Context>

请问怎么解决?

------解决方法--------------------------------------------------------
我今天也遇到了类似问题,不过我用的是tomcat5.0.27的,配置的语法不太一样,但道理是一样的。出现Name jdbc is not bound in this Context 说明他找不到你写的连接池资源配置文件。如果你把那些配置文件写入server.xml的context中就会出现这个问题。如果你写到 <GlobalNamingResources> </GlobalNamingResources> 之间就会出现org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class ' ' for connect URL 'null '这个问题
总结了两种解决方法:
(1)把资源配置写入 <GlobalNamingResources> </GlobalNamingResources> 之间
然后在conf/Catalina/localhost下面建立你的web描述文件比如你的web叫simplebbs你要建立simplebbs.xml在里面写入 <?xml version= "1.0 " encoding= "ISO-8859-1 "?>
<Context path= "/simplebbs " docBase= "${catalina.home}/webapps/simplebbs "
debug= "0 " privileged= "true ">
<ResourceLink name= "jdbc/bbs " global= "jdbc/bbs " type= "javax.sql.DataSource " />
</Context>
(2)server.xml中的 <context> </context> 之间只写:
<!-- new Context -->
<Context path= "simplebbs " docBase= "simplebbs "
debug= "100 " reloadable= "true " crossContext= "true ">

<Logger className= "org.apache.catalina.logger.FileLogger "
prefix= "localhost_SimpleBBS_log. " suffix= ".txt "
timestamp= "true "/>
</Context>
在conf/Catalina/localhost下面建立你的web描述文件比如你的web叫simplebbs你要建立simplebbs.xml在里面写入
<?xml version= "1.0 " encoding= "ISO-8859-1 "?>
<Context path= "/simplebbs " docBase= "${catalina.home}/webapps/simplebbs "
debug= "0 " privileged= "true ">
<Resource name= "jdbc/bbs "
auth= "Container "
type= "javax.sql.DataSource "/>
<ResourceParams name= "jdbc/bbs ">
<parameter>
<name> factory </name>
<value> org.apache.commons.dbcp.BasicDataSourceFactory </value>
</parameter>

<!-- Maximum number of dB connections in pool. Make sure you
configure your mysqld max_connections large enough to handle         

热点排行