If something doesn't fit in any other forum then post it here.
tukune
Posts: 533 Joined: Sun Mar 29, 2009 2:35 pm
Location: Japan
Post
by tukune » Sun Nov 06, 2011 6:08 pm
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); }
jurchiks
Posts: 6769 Joined: Sat Sep 19, 2009 4:16 pm
Location: Eastern Europe
Post
by jurchiks » Sun Nov 06, 2011 9:16 pm
That's good to know, but when does it close the connection?
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Stake
Posts: 383 Joined: Sun Mar 23, 2008 9:33 pm
Location: Hungary
Contact:
Post
by Stake » Sun Nov 06, 2011 10:29 pm
jurchiks wrote: That's good to know, but when does it close the connection?
I think, after it jumped out of try block.
JIV
L2j Veteran
Posts: 1882 Joined: Sun Jan 06, 2008 8:17 pm
Location: Slovakia
Contact:
Post
by JIV » Mon Nov 07, 2011 4:43 pm
is it automatically added into bytecode?
Stake
Posts: 383 Joined: Sun Mar 23, 2008 9:33 pm
Location: Hungary
Contact:
Post
by Stake » Mon Nov 07, 2011 7:01 pm
JIV wrote: is it automatically added into bytecode?
More probably. It doesn't seem to be a runtime check.