遇到这个异常,没法解决了 Operation not allowed after ResultSet closed-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

遇到这个异常,没法解决了 Operation not allowed after ResultSet closed

2016-07-04 15:52:52 2805 1

今天遇到一个诡异的问题。。

    public JsonArray getVideoList(String sql, String[] args) {
        JsonArray arr = new JsonArray();
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            conn = DBHelper.connectDB();
            ps = conn.prepareStatement(sql);
            if (args != null) {
                for (int i = 0; i < args.length; i++) {
                    ps.setObject(i + 1, args[i]);
                }
            }
            rs = ps.executeQuery();
            JsonObject entity;
            while (rs.next()) {
                entity = new JsonObject();
                entity.addProperty("id", rs.getString("id"));
                entity.addProperty("title", Utils.string2Unicode(rs.getString("post_title")));
                String json = rs.getString("smeta");
                if (Utils.isEmpty(json)) {
                    entity.addProperty("intro", "");
                } else {
                    JsonObject jo = new JsonParser().parse(json).getAsJsonObject();
                    entity.addProperty("intro", jo.get("thumb").getAsString());
                }
                String video_url = rs.getString("post_video");
                entity.addProperty("link", video_url);
                entity.addProperty("try_video", rs.getString("try_video"));
                entity.addProperty("duration", rs.getInt("video_duration"));
                entity.addProperty("type", rs.getInt("post_parent"));
                entity.addProperty("score", rs.getInt("post_score"));
                arr.add(entity);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                if (rs != null) {
                    rs.close();
                }
                if (ps != null) {
                    ps.close();
                }
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        return arr;
    }
异常信息如下

java.sql.SQLException: Operation not allowed after ResultSet closed
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
        at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:794)
        at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1105)
        at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5610)
        at com.thinkcmf.dao.ListDao.getVideoList(ListDao.java:100)
        at com.thinkcmf.model.MList.getVideoList(MList.java:45)
        at com.thinkcmf.servlet.List.doGet(List.java:43)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)
java.sql.SQLException: Operation not allowed after ResultSet closed
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:982)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)
        at com.mysql.jdbc.ResultSetImpl.checkClosed(ResultSetImpl.java:794)
        at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1105)
        at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5610)
        at com.thinkcmf.dao.ListDao.getVideoList(ListDao.java:93)
        at com.thinkcmf.model.MList.getVideoList(MList.java:45)
        at com.thinkcmf.servlet.List.doGet(List.java:43)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

然而我并没有在循环里边关闭rs或者conn啊。

怎么回事呢。。。。。。。

求指教 。

取消 提交回答
全部回答(1)
  • a123456678
    2019-07-17 19:50:46

    rs 不用强制关闭

    0 0
相关问答

1

回答

请问下,一个main里用sql执行两个executeInsert,提交任务时会自动把一个job拆分为

2022-09-21 16:40:15 228浏览量 回答数 1

1

回答

react native中的MaterialPageRoute是什么?

2022-09-21 20:47:59 100浏览量 回答数 1

1

回答

【OSS】挂载成功后,ls目录时出现“operation not permitted”报错,怎么办?

2022-01-19 15:00:10 466浏览量 回答数 1

1

回答

RDS MySQL出现“OPERATION need to be executed set by

2022-01-07 16:49:41 1258浏览量 回答数 1

1

回答

SerializationInfo的作用是什么?

2021-12-05 10:29:07 107浏览量 回答数 1

1

回答

dd /dev/mem 报错operation not permitted?报错

2020-06-08 12:43:06 462浏览量 回答数 1

1

回答

诚求《算法导论》即《Introduction to Algorithms》的电子版,非常感谢!

2018-07-22 16:43:38 1173浏览量 回答数 1

2

回答

挂载后收到operation not permitted错误

2018-05-05 11:39:03 5442浏览量 回答数 2

2

回答

Cannot load module modssl.soundefined symbolSSLgetsrpuserinfo

2017-05-26 19:12:04 3296浏览量 回答数 2

1

回答

求主办方给一个完整的可提交的demo

2015-07-21 22:05:20 6048浏览量 回答数 1
+关注
文章
问答
问答排行榜
最热
最新
相关电子书
更多
Why you should care about data
立即下载
Towards A Fault-Tolerant Speaker Verification System: A Regularization Approach To Reduce The Condition Number
立即下载
Why you should care about data layout in the file system
立即下载