SQL ERROR: Closed Connection in java -


connection closing automatically if i'm not closing in block.

 public string look( long id, string codename, connection conn ) throws sqlexception     {         try         {             stringbuffer sel = new stringbuffer().append(property);             stmt = conn.preparecall( sel.tostring() );           /*   filecode.java:194    */              stmt.setstring( 1, namec );             stmt.setlong( 2, valuei );             stmt.registeroutparameter( 3, oracle.jdbc.oracletypes.varchar );             stmt.execute();              return stmt.getstring( 3 );         }         catch ( sqlexception e )         {             if ( e.getmessage().touppercase().contains( "no data" ) )             {                 return "value not found";             }             throw e;         }         catch ( exception e )         {             e.printstacktrace();          }                 {             system.out.println( " connnnnn closed ? : " + conn.isclosed() );          }      } 

method calls method,

public class verfication      {         public void verify ( , , , , , , ,conn )     {       try       {          if ( x ==1 )          {            managecode mcode = new managecode();            system.out.println( "----- 1st call -----" );            string mcodeblock = mcode.look( , , conn);            string ccodeblocked = checkbackup ( , , , , , , , , );            /* connection closed in part */             system.out.println( "----- 2nd call -----" );            string ncodeblock = mcode.look ( , , conn );          }        }catch(    )       {        }      } }    

i output mentioned below, not sure wrong in connection ? have added system outs.

output:

     ----- 1st call -----      connnnnn closed ? : false       ----- 2nd call -----      connnnnn closed ? : true      severe: line:71 codepointchecker error: java.sql.sqlexception: closed connection     @ oracle.jdbc.driver.databaseerror.throwsqlexception(databaseerror.java:125)     @ oracle.jdbc.driver.databaseerror.throwsqlexception(databaseerror.java:162)     @ oracle.jdbc.driver.databaseerror.throwsqlexception(databaseerror.java:227)     @ oracle.jdbc.driver.physicalconnection.preparecall(physicalconnection.java:839)     @ oracle.jdbc.driver.physicalconnection.preparecall(physicalconnection.java:802)     @ com.xxxxxxxxxxxxxxx.code.filecode.look(filecode.java:194) 

jdbc connections can closed many reasons - not deliberately you. why there many connection pool implementations out there.

i have seen connections closing because port connection running through closed. have seen connections closed just because database felt it (mostly oracle one).

of course - obvious possibility closing connection accident somewhere else - perhaps in thread.

moral - use proper connection pool. save grief.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -