Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Which databases are the most used with Java Date: Tue, 15 Aug 2017 11:51:23 -0400 Organization: Aioe.org NNTP Server Lines: 39 Message-ID: References: <87y3qovwjb.fsf@munus.decebal.nl> <87tw1bx2c9.fsf@munus.decebal.nl> <87a833wzcx.fsf@munus.decebal.nl> <87pobz9yv5.fsf@munus.decebal.nl> <87h8x9pfi8.fsf@munus.decebal.nl> <877ey5ngtu.fsf@munus.decebal.nl> <6b0c0b97-8517-4f08-b512-fc3f3054fbb6@googlegroups.com> <87378soq8a.fsf@munus.decebal.nl> <54246758-9876-4f41-a7ac-c2fff223a9e0@googlegroups.com> NNTP-Posting-Host: LO3gx2vFpREKIznvPHDlcg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:37248 On 8/15/2017 11:43 AM, Eric Douglas wrote: > Here's another simple example, look one Statement instance, two ResultSet instance. > > public static void main(final String[] args) { > try { > Connection conn = DriverManager.getConnection(db_connect_string, db_userid, db_password); > Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); > ResultSet rs = stmt.executeQuery("SELECT table_name FROM information_schema.tables"); > System.out.println(stmt.getClass()); > rs.last(); > System.out.println(rs.getRow()); > rs.close(); > rs = stmt.executeQuery("SELECT name from sys.columns"); I don't think I would reuse the variable. > rs.last(); > System.out.println(rs.getRow()); > rs.close(); > stmt.close(); > conn.close(); > } catch (SQLException e) { > e.printStackTrace(); > } > } > The close methods are optional. Connection close is definitely not optional. > Anything you ultimately fail to close should > close itself in a cleanup section. Yes. Either catch or finally should close. Or the new try with resource should be used instead. Arne