Skip to content

Commit 11ef9e5

Browse files
committed
Use try with resources
1 parent 73bb838 commit 11ef9e5

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/test/java/examples/animal/data/BindingTest.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ void setup() throws Exception {
6666

6767
@Test
6868
void testBindInSelectList() {
69-
SqlSession sqlSession = sqlSessionFactory.openSession();
70-
try {
69+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
7170
Connection connection = sqlSession.getConnection();
7271

7372
PreparedStatement ps = connection.prepareStatement("select brain_weight + ? as calc from AnimalData where id = ?");
@@ -86,15 +85,12 @@ void testBindInSelectList() {
8685
assertThat(calculatedWeight).isEqualTo(1.005);
8786
} catch (SQLException e) {
8887
fail("SQL Exception", e);
89-
} finally {
90-
sqlSession.close();
9188
}
9289
}
9390

9491
@Test
9592
void testBindInWeirdWhere() {
96-
SqlSession sqlSession = sqlSessionFactory.openSession();
97-
try {
93+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
9894
Connection connection = sqlSession.getConnection();
9995

10096
PreparedStatement ps = connection.prepareStatement("select brain_weight from AnimalData where brain_weight + ? > ? and id = ?");
@@ -114,8 +110,6 @@ void testBindInWeirdWhere() {
114110
assertThat(calculatedWeight).isEqualTo(.005);
115111
} catch (SQLException e) {
116112
fail("SQL Exception", e);
117-
} finally {
118-
sqlSession.close();
119113
}
120114
}
121115
}

0 commit comments

Comments
 (0)