java -- try-with-resources statement
java -- try-with-resources statement
참고 : https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
http://stackoverflow.com/questions/8066501/how-should-i-use-try-with-resources-with-jdbc
http://www.javacodegeeks.com/2011/07/java-7-try-with-resources-explained.html
Java SE 7 부터 지원하는 기능.
하나 이상의 resource ( 프로그램이 사용후 close 해야 하는 object ) 를 선언하는 try statement.
statement 가 끝나면, resource 는 자동으로 close 된다. (이를 보장한다)
** java.lang.AutoCloseable 을 구현한 객체는 try-with-resources statement 의 resource 가 될수있다.
catch & finally blocks 을 가질수 있다.
catch or finally block 은, 선언된 resource 가 close 된후 실행된다.
Java SE 7 이전에는 finally block 으로 close 해줘야 했다.
<< 사용 예 비교 >>
1. try-with-resources Statement 사용한 경우 ( Java SE 7 이후 )
2. finally block 사용한 경우 ( Java SE 7 이전 )