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