Page 1 of 1
java7 Connection implements AutoCloseable
Posted: Sun Nov 06, 2011 6:08 pm
by tukune
Code: Select all
- java.sql.Connection con = null;- try- {- con = L2DatabaseFactory.getInstance().getConnection();+ try (Connection con = L2DatabaseFactory.getInstance().getConnection())+ { PreparedStatement statement = con.prepareStatement("SELECT * FROM `foo`"); ResultSet rs= statement.executeQuery(); ..... } catch (Exception e) { ..... }- finally { L2DatabaseFactory.close(con); }
Re: java7 Connection implements AutoCloseable
Posted: Sun Nov 06, 2011 9:16 pm
by jurchiks
That's good to know, but when does it close the connection?
Re: java7 Connection implements AutoCloseable
Posted: Sun Nov 06, 2011 10:29 pm
by Stake
jurchiks wrote:That's good to know, but when does it close the connection?
I think, after it jumped out of try block.
Re: java7 Connection implements AutoCloseable
Posted: Mon Nov 07, 2011 4:43 pm
by JIV
is it automatically added into bytecode?
Re: java7 Connection implements AutoCloseable
Posted: Mon Nov 07, 2011 7:01 pm
by Stake
JIV wrote:is it automatically added into bytecode?
More probably. It doesn't seem to be a runtime check.
