java - PreparedStatement Close Issue for MySQLNonTransientConnectionException: -


i unable locate following exception occurs. have closed preparedstatement after loop finishes, still gives me error while calling sendbill method:

exception text:

com.mysql.jdbc.exceptions.jdbc4.mysqlnontransientconnectionexception:  no operations allowed after statement closed.  @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)  @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:39)  @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:27)  @ java.lang.reflect.constructor.newinstance(constructor.java:513)  @ com.mysql.jdbc.util.handlenewinstance(util.java:411)  @ com.mysql.jdbc.util.getinstance(util.java:386)  @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:1015)  @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:989)  @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:975)  @ com.mysql.jdbc.sqlerror.createsqlexception(sqlerror.java:920)  @ com.mysql.jdbc.statementimpl.checkclosed(statementimpl.java:461) 

relevant code:

void executebills() {     try{         preparedstatement prestatementupdate = null;         preparedstatement prestatementinsert = null;          if(prestatementupdate==null || prestatementupdate.isclosed())                     prestatementupdate = con.preparestatement(sqlupdatequery);          if(prestatementinsert==null || prestatementinsert.isclosed())             prestatementinsert = con.preparestatement(sqlinsertquery);           for(int i=0;i<countrylist.size();i++)         {             country=countrylist.get(i);              //error shown on line no.              sendbill(country,prestatementupdate,prestatementinsert)          }      }catch(exception e) {         e.printstacktrace();     }finally{         //closing preparedstatement         prestatementupdate.close();         prestatementinsert.close();     }  }  void sendbill(string country, preparedstatement _1, preparedstatement _2) {      //code of preparedstatement setting string parameter..       //...error shown on line no.       //getcreditamount returns int,  string.valueof used      _1.setstring(1,string.valueof(country.getcreditamount()));         _1.executeupdate() ;       _2.executeupdate();        //no closing preparedstatement here  } 


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -