java - SQL Exception: Operation not allowed after ResultSet closed -


i exception"operation not allowed after resultset closed", function close resultset every time. should add 'synchronized' function? or how solve exception?

        public static arraylist<region> gethotproductregionlist() {              arraylist<region> list = new arraylist<region>();              resultset rs = null;             conn.checkconn();             try {                     if (gethotproductregionstmt==null) gethotproductregionstmt = conn.preparestatement(gethotproductregionstr);                     rs = gethotproductregionstmt.executequery();                     if (rs!=null) {                             while (rs.next()) {                                     region r = new region();                                     setregion(r, rs);                                     list.add(r);                             }                             rs.close();                     }             } catch (exception e) {                     j.m("regionmanager.gethotproductregion exception: " + e.getmessage());                     e.printstacktrace();             }             if (rs!=null) try { rs.close(); } catch (exception ex) {}             return list;     }     private static preparedstatement gethotproductregionstmt = null;     private static string gethotproductregionstr = " select * region"; 

and preparedstatement reset code:

        private static dbconn conn = new dbconn("regionmanager") {             public void resetall() {                     gethotproductregionstmt = reset(gethotproductregionstmt);                               }     }; 

your whole approach wrong here. should looking use new, local, connection , preparedstatement per invocation of method, , close them afterwards, , use connection pooling mitigate effects. using static connection not thread-safe, , using static preparedstatement never going work.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -