1、c3p0-config.xml要放在src目录下,而不是WEB-INF目录下
2、在测试时
PreparedStatement pstmt = (PreparedStatement)conn.prepareStatement(sql);
使用是应该是java.sql.PreparedSatement, 而不是mysql的PreparedStatement.
因为c3p0使用的是java.sql.PreparedSatement, 如果不一致会无法转换。
错误如下:
java.lang.ClassCastException: com.mchange.v2.c3p0.impl.NewProxyPreparedStatement cannot be cast to com.mysql.jdbc.PreparedStatement at db.C3P0Utils.test(C3P0Utils.java:38) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.Na