The connection closes automatically, even if I do not close the finally block.
public String look( long id, String codeName, Connection conn ) throws SQLException { try { StringBuffer sel = new StringBuffer().append(property); stmt = conn.prepareCall( sel.toString() ); 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(); } finally { System.out.println( " CONNNNNN closed ? : " + conn.isClosed() ); } }
Method call method search,
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 ( , , , , , , , , ); System.out.println( "----- 2nd Call -----" ); String nCodeBlock = mCode.look ( , , conn ); } }catch( ) { } } }
I get the output as below, I'm not sure what is wrong with the connection? I also added system outputs.
Output:
----- 1st Call ----- CONNNNNN closed ? : false ----- 2nd Call ----- CONNNNNN closed ? : true SEVERE: Line:71 CodePointChecker ERROR: java.sql.SQLException: Closed Connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:227) at oracle.jdbc.driver.PhysicalConnection.prepareCall(PhysicalConnection.java:839) at oracle.jdbc.driver.PhysicalConnection.prepareCall(PhysicalConnection.java:802) at com.XXXXXXXXXXXXXXX.code.fileCode.look(fileCode.java:194)