DatabaseConnection implements AutoCloseable v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 23 Dec 2013 16:29:51 +0100
branchv_0
changeset 426fdaa4db3943
parent 41 514df5061f59
child 43 2813d3409afd
DatabaseConnection implements AutoCloseable
java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Mon Dec 23 16:19:21 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Mon Dec 23 16:29:51 2013 +0100
     1.3 @@ -109,9 +109,10 @@
     1.4  			if (fd == null) {
     1.5  				throw new ConfigurationException("Formatter is not configured: " + options.getFormatterName());
     1.6  			} else {
     1.7 -				DatabaseConnection c = dd.connect();
     1.8 -				Formatter f = fd.getInstance(new FormatterContext(options.getOutputStream()));
     1.9 -				c.executeQuery(options.getSQLCommand(), f);
    1.10 +				try (DatabaseConnection c = dd.connect()) {
    1.11 +					Formatter f = fd.getInstance(new FormatterContext(options.getOutputStream()));
    1.12 +					c.executeQuery(options.getSQLCommand(), f);
    1.13 +				}
    1.14  			}
    1.15  		}
    1.16  	}
     2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Mon Dec 23 16:19:21 2013 +0100
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/DatabaseConnection.java	Mon Dec 23 16:29:51 2013 +0100
     2.3 @@ -31,7 +31,7 @@
     2.4   *
     2.5   * @author Ing. František Kučera (frantovo.cz)
     2.6   */
     2.7 -public class DatabaseConnection {
     2.8 +public class DatabaseConnection implements AutoCloseable {
     2.9  
    2.10  	private DatabaseDefinition databaseDefinition;
    2.11  	private Connection connection;
    2.12 @@ -114,4 +114,9 @@
    2.13  		}
    2.14  
    2.15  	}
    2.16 +
    2.17 +	@Override
    2.18 +	public void close() throws SQLException {
    2.19 +		connection.close();
    2.20 +	}
    2.21  }