# HG changeset patch # User František Kučera # Date 1387812591 -3600 # Node ID 6fdaa4db39437b41e9e16e0e7fb4f65ac1b27bd0 # Parent 514df5061f590e03c47590178046804492fd8355 DatabaseConnection implements AutoCloseable diff -r 514df5061f59 -r 6fdaa4db3943 java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java --- 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); + } } } } diff -r 514df5061f59 -r 6fdaa4db3943 java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java --- 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(); + } }