mysql-connector-java-5.0.3-bin.jar中的Preparedstatement居然没有isClosed()方法

白天为项目写新增,本以为一个很简单的操作,没想到又遇到了麻烦,每次新增的时候,总是提示报错:

2016-2-20 0:43:25 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet UsersAction threw exception
java.lang.AbstractMethodError: com.mysql.jdbc.ServerPreparedStatement.isClosed()Z
	at com.cc.dao.impl.BaseDao.closeAll(BaseDao.java:95)
	at com.cc.dao.impl.UserDaoImpl.addUsers(UserDaoImpl.java:46)
	at com.cc.service.impl.UsersServiceImpl.addUsers(UsersServiceImpl.java:83)
	at com.cc.action.UsersAction.addUsers(UsersAction.java:68)
	at com.cc.action.UsersAction.doPost(UsersAction.java:47)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
	at java.lang.Thread.run(Thread.java:619)

多次百度无果,经过多次测试,终于发现,在判断ResultSet、PreparedStatement以及Connection的状态的时候,是这样写的
 
  
public void closeAll(){
	if(this.rs!=null){
		try {
			if(!this.rs.isClosed()){
				this.rs.close();
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	if(this.ps!=null){
		try {
			if(!this.ps.isClosed()){
				
				this.ps.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	if(this.con!=null){
		try {
			if(!this.con.isClosed()){
				this.con.close();
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}

问题原因:与Oracle不同,mysql的jar包里面的ResultSet、PreparedStatement以及Connection是没有.isClose()方法的。
解决办法:注释掉判断三者.isClosed()的if语句即可。。。

为了找答案,又费了好大的劲。。。我就纳闷了,你没有这个方法你咋不在代码里提示呢?一定要报个错才可以。。。

你可能感兴趣的:(javaweb)