问题描述
我在一个web项目中用到了Mysql数据库,并且JDBC进行数据库连接,我设置setAutoCommit(false)使用事务控制。开始启动项目的时候都能正常使用。但是当我把电脑一直开启tomcat服务超过一天之后就会报错。错误提示:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:Can'tcallrollbackwhenautocommit=true。但是项目中明明设置了setAutoCommit(false),而且开始也是正常的,为什么在使用一段时间后会autocommit=true呢?而且我电脑是win7系统,后来我换一台XP系统的电脑就不会出现上述情况。求高手解答。下面是错误的堆栈信息:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:Can'tcallrollbackwhenautocommit=truesun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod)sun.reflect.NativeConstructorAccessorImpl.newInstance(UnknownSource)sun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnknownSource)java.lang.reflect.Constructor.newInstance(UnknownSource)com.mysql.jdbc.Util.handleNewInstance(Util.java:406)com.mysql.jdbc.Util.getInstance(Util.java:381)com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4748)org.apache.commons.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:328)org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:312)com.wrt.community.interceptor.TransactionInterceptor.intercept(TransactionInterceptor.java:24)com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)