Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: None  |  size: 0.48 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is it necessary to close connection and statement when method terminates?
  2. void databaseCall() {
  3.     Connection con = null;
  4.     Statement statement = null        
  5.     try {      
  6.           con = getConnection(...);    
  7.           statement = con.createStatement(...);        
  8.           // do some query
  9.     } catch (SQLException e) {
  10.          // bla bla
  11.     } finally {
  12.          try {con.close();} catch (Exception e1) {}
  13.          try {statement.close();} catch (Exception e1) {}
  14.     }
  15. }