--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Mon Dec 23 16:19:21 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Mon Dec 23 16:29:51 2013 +0100
@@ -109,9 +109,10 @@
if (fd == null) {
throw new ConfigurationException("Formatter is not configured: " + options.getFormatterName());
} else {
- DatabaseConnection c = dd.connect();
- Formatter f = fd.getInstance(new FormatterContext(options.getOutputStream()));
- c.executeQuery(options.getSQLCommand(), f);
+ try (DatabaseConnection c = dd.connect()) {
+ Formatter f = fd.getInstance(new FormatterContext(options.getOutputStream()));
+ c.executeQuery(options.getSQLCommand(), f);
+ }
}
}
}
--- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Mon Dec 23 16:19:21 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java Mon Dec 23 16:29:51 2013 +0100
@@ -31,7 +31,7 @@
*
* @author Ing. František Kučera (frantovo.cz)
*/
-public class DatabaseConnection {
+public class DatabaseConnection implements AutoCloseable {
private DatabaseDefinition databaseDefinition;
private Connection connection;
@@ -114,4 +114,9 @@
}
}
+
+ @Override
+ public void close() throws SQLException {
+ connection.close();
+ }
}