Instead of holding the connection open for the duration of the application,
open a fresh connection for each command, and close it immediately after the
command completes. This may reduce the risk of having connections hang around
for a while, if the JVM terminates unexpectedly (e.g., if the ssh session gets
killed and the console goes away).
<groupId>net.jaekl.squelch</groupId>
<artifactId>squelch</artifactId>
<packaging>jar</packaging>
<groupId>net.jaekl.squelch</groupId>
<artifactId>squelch</artifactId>
<packaging>jar</packaging>
+ <version>0.1a-SNAPSHOT</version>
<name>squelch</name>
<url>http://maven.apache.org</url>
<build>
<name>squelch</name>
<url>http://maven.apache.org</url>
<build>
String jdbcUrl = m_args.getUrl();
DbDriver driver = getDriverFor(jdbcUrl);
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;
+ // Unrecognized command
+ // TODO: add a string table, and a natural-language error message.
+ pw.println("??? \"" + line + "\"");