@@ -222,9 +222,9 @@ private Connection geH2Connection() throws SQLException, ClassNotFoundException
222222 public void testJdbcPrinter () throws IOException , ClassNotFoundException , SQLException {
223223 final StringWriter sw = new StringWriter ();
224224 final Connection connection = geH2Connection ();
225+ setUpTable (connection );
225226 try {
226227 final Statement stmt = connection .createStatement ();
227- setUpTable (stmt );
228228 final CSVPrinter printer = new CSVPrinter (sw , CSVFormat .DEFAULT );
229229 printer .printRecords (stmt .executeQuery ("select ID, NAME from TEST" ));
230230 assertEquals ("1,r1" + recordSeparator + "2,r2" + recordSeparator , sw .toString ());
@@ -239,11 +239,11 @@ public void testJdbcPrinterWithResultSet() throws IOException, ClassNotFoundExce
239239 final StringWriter sw = new StringWriter ();
240240 Class .forName ("org.h2.Driver" );
241241 final Connection connection = geH2Connection ();
242+ setUpTable (connection );
242243 try {
243244 @ SuppressWarnings ("resource" )
244245 // Closed when the connection is closed.
245246 final Statement stmt = connection .createStatement ();
246- setUpTable (stmt );
247247 @ SuppressWarnings ("resource" )
248248 // Closed when the connection is closed.
249249 final ResultSet resultSet = stmt .executeQuery ("select ID, NAME from TEST" );
@@ -262,11 +262,11 @@ public void testJdbcPrinterWithResultSetMetaData() throws IOException, ClassNotF
262262 final StringWriter sw = new StringWriter ();
263263 Class .forName ("org.h2.Driver" );
264264 final Connection connection = geH2Connection ();
265+ setUpTable (connection );
265266 try {
266267 @ SuppressWarnings ("resource" )
267268 // Closed when the connection is closed.
268269 final Statement stmt = connection .createStatement ();
269- setUpTable (stmt );
270270 @ SuppressWarnings ("resource" )
271271 // Closed when the connection is closed.
272272 final ResultSet resultSet = stmt .executeQuery ("select ID, NAME from TEST" );
@@ -280,10 +280,15 @@ public void testJdbcPrinterWithResultSetMetaData() throws IOException, ClassNotF
280280 }
281281 }
282282
283- private void setUpTable (final Statement stmt ) throws SQLException {
284- stmt .execute ("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))" );
285- stmt .execute ("insert into TEST values(1, 'r1')" );
286- stmt .execute ("insert into TEST values(2, 'r2')" );
283+ private void setUpTable (final Connection connection ) throws SQLException {
284+ Statement statement = connection .createStatement ();
285+ try {
286+ statement .execute ("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))" );
287+ statement .execute ("insert into TEST values(1, 'r1')" );
288+ statement .execute ("insert into TEST values(2, 'r2')" );
289+ } finally {
290+ statement .close ();
291+ }
287292 }
288293
289294 @ Test
0 commit comments