简体   繁体   中英

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 obviously results in ClassCastException ). Just wondering why no change in code and context.xml would result in returning two different implementations of DataSource?

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

I suppose you are not including DBCP inside your war. So it's using whatever DataSource is configured in Tomcat. You're probably using two different versions of Tomcat, or at least they have been configured differently; one must have commons-dbcp.jar and the other one has tomcat-dbcp.jar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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