`

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

阅读更多
Tomcat配置连接池的问题。

异常:javax.naming.NameNotFoundException: Name jdbc is not bound in this Context


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");

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics