Sonar fix for DB.java
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / utils / DB.java
index a907a03..7f0d56b 100644 (file)
@@ -38,14 +38,12 @@ import java.util.*;
  */\r
 public class DB {\r
 \r
-    /**\r
-     * The name of the properties file (in CLASSPATH)\r
-     */\r
+    private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");\r
+\r
     private static String DB_URL;\r
     private static String DB_LOGIN;\r
     private static String DB_PASSWORD;\r
     private static Properties props;\r
-    private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");\r
     private static final Queue<Connection> queue = new LinkedList<>();\r
 \r
     public static String HTTPS_PORT;\r
@@ -114,13 +112,16 @@ public class DB {
                                 throw sqlEx;\r
                             }\r
                         }\r
+                        finally {\r
+                            if (connection != null && !connection.isValid(1)) {\r
+                                connection.close();\r
+                                connection = null;\r
+                            }\r
+                        }\r
                     } while (connection == null);\r
                 }\r
             }\r
-            if (connection != null && !connection.isValid(1)) {\r
-                connection.close();\r
-                connection = null;\r
-            }\r
+\r
         }\r
         return connection;\r
     }\r