Try with Resource implemented for automatic connection closing