java.sql.SQLException:ResultSet关闭后不允许操作6

时间:2016-06-08 12:23:23

标签: java sql

首先,我是这个java的新手。这是我的代码:

public class functions {

private static Connection connection;
private static ArrayList<MapModel> list = new ArrayList<MapModel>();
private static Cipher cipher;

public static ArrayList<MapModel> getAllId(String report_type, String dist_code){
    ArrayList<MapModel> idList = new ArrayList<MapModel>();
    ResultSet rs = null;
    Statement statement = null;
    try {

        connection = DBconnection.getConnection();
        System.out.println(connection.getMetaData());
        statement = connection.createStatement();
        String sproc=null;
        sproc="call load_district('" + report_type + "','" + dist_code + "')";
        System.out.println("call load_district('" + report_type + "','" + dist_code + "')");
        CallableStatement cstmt = connection.prepareCall("{"+sproc+"}");
        rs = cstmt.executeQuery();

        System.out.println(rs.isClosed());
        System.out.println(statement.isClosed());
        System.out.println(connection.isClosed());
        if (!rs.isBeforeFirst()) {
            System.out.println("no data");
        } else {
            while (rs.next()) {
                //some data
            }
        }

    } catch (Exception e) {

        e.printStackTrace();

    } finally {
        try {
            // just to check
            System.out.println("m closing all");
            System.out.println(rs.isClosed());
            System.out.println(statement.isClosed());
            System.out.println(connection.isClosed());
            // ---end---
            DbUtils.closeQuietly(statement);
            DbUtils.closeQuietly(rs);
            DbUtils.closeQuietly(connection);
        } catch (SQLException ex) {
            Logger.getLogger(functions.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    return idList;

}

}

并非总是如此,但有时我会收到此错误:

Info:   call load_district('someval','someval')
Info:   false
Info:   true
Info:   true
Info:   m closing all
Info:   true
Info:   true
Info:   true
Severe:   java.sql.SQLException: Operation not allowed after ResultSet closed

我不明白为什么语句和连接在关闭之前处于关闭状态。

0 个答案:

没有答案