Tomcat配置连接池 异常:javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Tomcat配置连接池的问题。
web工程下的,WEB-INF下的web.xml添加这一段:

<resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/mysqlx</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
  </resource-ref>

相对应的jsp或者java代码应该为:

DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/mysqlx");

或者

Context envCtx = (Context) ctx.lookup("java:comp/env");
DataSource ds = (DataSource) ctx.lookup("jdbc/mysqlx");

posted @ 2011-03-11 08:20  lishoubin  阅读(826)  评论(0编辑  收藏  举报