Java 7 Project Coin: try-with-resources explained with examples

Prior to “try-with-resources” (before Java 7) while dealing with SQL Statement or ResultSet or Connection objects or other IO objects one had to explicitly close the resource. So one would write something like-

try{
  //Create a resource- R
}catch(SomeException e){
  //Hanlde the exception
}finally{
  //if resource R is not null then
  try{
    //close the resource
  }
  catch(SomeOtherException ex){
  }
}

Read more

%d bloggers like this: