/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache license, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the license for the specific language governing permissions and
 * limitations under the license.
 */
package org.apache.logging.log4j.core.appender.db.jpa;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.logging.log4j.util.Strings;

public class JpaH2AppenderTest extends AbstractJpaAppenderTest {
    private static final String USER_ID = "sa";
    private static final String PASSWORD = Strings.EMPTY;

    public JpaH2AppenderTest() {
        super("h2");
    }

    @Override
    protected Connection setUpConnection() throws SQLException {
        final Connection connection = DriverManager.getConnection("jdbc:h2:mem:Log4j", USER_ID, PASSWORD);

        Statement statement = connection.createStatement();
        statement.executeUpdate("CREATE TABLE jpaBaseLogEntry ( " +
                "id INTEGER IDENTITY, eventDate DATETIME, level NVARCHAR(10), logger NVARCHAR(255), " +
                "message NVARCHAR(1024), exception NVARCHAR(1048576)" +
                " )");
        statement.close();

        statement = connection.createStatement();
        statement.executeUpdate("CREATE TABLE jpaBasicLogEntry ( " +
                "id INTEGER IDENTITY, timemillis BIGINT, nanoTime BIGINT, level NVARCHAR(10), loggerName NVARCHAR(255), " +
                "message NVARCHAR(1024), thrown NVARCHAR(1048576), contextMapJson NVARCHAR(1048576)," +
                "loggerFQCN NVARCHAR(1024), contextStack NVARCHAR(1048576), marker NVARCHAR(255), source NVARCHAR(2048)," +
                "threadId BIGINT, threadName NVARCHAR(255), threadPriority INTEGER" +
                " )");
        statement.close();

        return connection;
    }
}

@@ -1442,16 +1442,21 @@
         
+try (
 Statemen
@@ -1493,34 +1493,37 @@
 eStatement()
-;%0A
+) %7B%0A 
         
 statement.ex
@@ -1502,32 +1502,35 @@
 t()) %7B%0A         
+   
 statement.execut
@@ -1562,35 +1562,37 @@
 BaseLogEntry ( %22
- +%0A
+%0A    
                 
@@ -1582,32 +1582,34 @@
                 
+ +
  %22id INTEGER IDE
@@ -1670,34 +1670,32 @@
 NVARCHAR(255), %22
- +
 %0A               
@@ -1686,32 +1686,38 @@
 %0A               
+     +
  %22message NVARCH
@@ -1756,16 +1756,23 @@
 8576)%22 +
+ %22 )%22);
 %0A       
@@ -1776,58 +1776,33 @@
     
-  
+%7D%0A%0A
       
-%22 )%22);%0A        statement.close();%0A%0A       
+  try (Statement
  sta
@@ -1838,18 +1838,24 @@
 tement()
-;%0A
+) %7B%0A    
         
@@ -1912,18 +1912,16 @@
 ntry ( %22
- +
 %0A       
@@ -1928,16 +1928,22 @@
         
+     +
  %22id INT
@@ -2040,19 +2040,18 @@
 (255), %22
- +
 %0A
+ 
         
@@ -2057,16 +2057,21 @@
         
+    +
  %22messag
@@ -2148,19 +2148,22 @@
 48576),%22
- +%0A
+%0A     
         
@@ -2169,16 +2169,17 @@
         
++
  %22logger
@@ -2276,19 +2276,22 @@
 (2048),%22
- +%0A
+%0A     
         
@@ -2297,16 +2297,17 @@
         
++
  %22thread
@@ -2372,58 +2372,25 @@
 R%22 +
-%0A                %22 )%22);%0A        statement.close();
+ %22 )%22);%0A        %7D
 %0A%0A  

Use try-with-resources for JDBC resources.