我有以下代码。相当标准的东西。但是,我在if(!stmt.isClose())行上获得了非法访问异常......错误表明这是因为语句已关闭。这不是那个方法调用的重点吗?有人对此有一些想法吗?
Connection conn = dataSource.getConnection();
conn.setAutoCommit(false);
Statement stmt = conn.createStatement();
try {
stmt.executeUpdate(updateQuery1);
stmt.executeUpdate(updateQuery2);
stmt.executeUpdate(updateQuery3);
conn.commit();
try {
if (!stmt.isClosed()) {
stmt.close();
}
if (!conn.isClosed()) {
conn.close();
}
} catch (Throwable ignored) {
} catch(Throwable ignored) {
}
499285 java.lang.IllegalAccessError: org.apache.tomcat.dbcp.dbcp.DelegatingStatement.isClosed()Z
499286 at com.millennialmedia.enterprise.services.impl.CampaignUtilServiceImpl.resetExceptionCampaign(CampaignUtilServiceImpl.java:80)
499287 at com.millennialmedia.rest.services.CampaignUtilRESTService$1.process(CampaignUtilRESTService.java:55)
499288 at com.millennialmedia.rest.services.CampaignUtilRESTService$1.process(CampaignUtilRESTService.java:49)
499289 at com.millennialmedia.services.util.Processor.doProcess(Processor.java:98)
499290 at com.millennialmedia.rest.services.CampaignUtilRESTService.resetExceptionCampaign(CampaignUtilRESTService.java:49)
499291 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
499292 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
499293 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
499294 at java.lang.reflect.Method.invoke(Method.java:597)
499295 at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
499296 at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchPro
499297 at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
499298 at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
499299 at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
499300 at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
499301 at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
499302 at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
499303 at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
499304 at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
499305 at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
499306 at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
499307 at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
499308 at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
499309 at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
499310 at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
499311 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
499312 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
499313 at com.millennialmedia.instrumentation.MethodInvocationFilter._doFilter(MethodInvocationFilter.java:20)
499314 at com.millennialmedia.instrumentation.MethodInvocationFilter.doFilter(MethodInvocationFilter.java:31)
499315 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
499316 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
499317 at com.millennialmedia.session.BaseAuthenticatedUserFilter.doFilter(BaseAuthenticatedUserFilter.java:249)
499318 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
499319 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
499320 at com.millennialmedia.session.HibernateSessionRequestFilter.doFilter(HibernateSessionRequestFilter.java:57)
499321 at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
499322 at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
499323 at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
499324 at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
499325 at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
499326 at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
499327 at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
499328 at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
499329 at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
499330 at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
499331 at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
答案 0 :(得分:5)
我知道这篇文章已经过时,但自从我今天遇到这个问题以来,我想我可以节省一些时间。 你得到这个错误的原因是你使用的是pre Java 6(和pre-JDBC-4之前的)Tomcat-Version,其中
java.sql.Statement.isClosed()
不是界面的一部分:
http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/Statement.html
但在Java 6中,它是:
http://docs.oracle.com/javase/6/docs/api/java/sql/Statement.html#isClosed%28%29
请参阅isClosed()的方法可见性
VS。这里:
对当前DelegatingStatement的isClose()的评论说:
/*
* Note was protected prior to JDBC 4
* TODO Consider adding build flags to make this protected unless we are
* using JDBC 4.
*/
public boolean isClosed() throws SQLException {
return _closed;
}
答案 1 :(得分:0)
我不明白你为什么要测试它。此声明不可能在此时关闭,因此不要测试它,只需关闭它。同上连接。事实上,如果已经关闭,那么这两种密切方法都被指定为什么都不做。
不要给百合花镀金。
答案 2 :(得分:0)
问题是由于数据源为您提供的PreparedStatement的实现。 如果您查看提供的跟踪信息,可以看到以下内容:
499285 java.lang.IllegalAccessError:org.apache.tomcat.dbcp.dbcp.DelegatingStatement.isClosed()Z
这意味着您使用的PreparedStatement的实现是org.apache.tomcat.dbcp.dbcp.DelegatingStatement类的实例。如果您查看版本1.2.2,则方法 isClosed()受保护,因此,任何尝试访问此方法的尝试都会导致java.lang.IllegalAccessError。该库的其余版本(1.3及更高版本)将此修饰符公开了,因此您只需更改库版本即可解决此问题。