繁体   English   中英

JDBC 数据源

[英]JDBC DataSource

When I run the following code on one machine I get tomcat implementation of org.apache.tomcat.dbcp.dbcp.BasicDataSource and when I run it on another machine I get apache commons implementations of org.apache.commons.dbcp.BasicDataSource (which显然会导致ClassCastException )。 只是想知道为什么代码和上下文没有变化context.xml会导致返回两个不同的 DataSource 实现?

Context context = (Context) initialContext.lookup("java:/comp/env");
return (DataSource) context.lookup("jdbc/dbName");

我想你没有在你的战争中包括 DBCP。 所以它使用 Tomcat 中配置的任何 DataSource。 您可能正在使用两个不同版本的 Tomcat,或者至少它们的配置不同; 一个必须有commons-dbcp.jar,另一个必须有tomcat-dbcp.jar。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM