Opens and closes the JDBC connection for each command
[squelch.git] / src / main / java / net / jaekl / squelch / Squelch.java
index 848ede7db05c9a5d88c783f66bd250a7c4211e55..7b43bd21746170c0fd322ff3a5c73a974ef53d5f 100644 (file)
@@ -100,35 +100,32 @@ public class Squelch {
                String jdbcUrl = m_args.getUrl();
                DbDriver driver = getDriverFor(jdbcUrl);
 
-               try (Connection conn = getConnection(driver, jdbcUrl))
-               {
-                       while (true) {
-                               boolean processed = false;
-                               line = ci.readLine(PROMPT);
-                               
-                               for (Stmt statement : m_statements) {
-                                       if (statement.handles(line)) {
-                                               try {
-                                                       statement.exec(driver, conn, pw, line);
-                                               }
-                                               catch (SQLException exc) {
-                                                       exc.printStackTrace(pw);
-                                               }
-                                               processed = true;
-                                               break;
+               while (true) {
+                       boolean processed = false;
+                       line = ci.readLine(PROMPT);
+                       
+                       for (Stmt statement : m_statements) {
+                               if (statement.handles(line)) {
+                                       try (Connection conn = getConnection(driver, jdbcUrl)){
+                                               statement.exec(driver, conn, pw, line);
                                        }
-                               }
-                               
-                               if ((!processed)) {
-                                       if (isQuit(line)) {
-                                               break;
+                                       catch (SQLException exc) {
+                                               exc.printStackTrace(pw);
                                        }
-                                       // Unrecognized command
-                                       // TODO:  add a string table, and a natural-language error message.
-                                       pw.println("??? \"" + line + "\"");
+                                       processed = true;
+                                       break;
+                               }
+                       }
+                       
+                       if ((!processed)) {
+                               if (isQuit(line)) {
+                                       break;
                                }
-                               pw.flush();
+                               // Unrecognized command
+                               // TODO:  add a string table, and a natural-language error message.
+                               pw.println("??? \"" + line + "\"");
                        }
+                       pw.flush();
                }
        }       
 }