Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Which databases are the most used with Java Date: Mon, 21 Aug 2017 22:25:56 +0200 Lines: 30 Message-ID: References: <87y3qovwjb.fsf@munus.decebal.nl> <87tw1bx2c9.fsf@munus.decebal.nl> <87a833wzcx.fsf@munus.decebal.nl> <87pobz9yv5.fsf@munus.decebal.nl> <871sofrwsk.fsf@munus.decebal.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net MQ9jrSHsk+U8wg/DRjGOhwS25pFhVOf3CUrYzz/t5NAVchy+U= Cancel-Lock: sha1:6+EGyTEMHToinNpC/1w2twdmFnU= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:37330 On 14.08.2017 02:41, Arne Vajh=C3=B8j wrote: > On 8/13/2017 5:18 PM, Cecil Westerhof wrote: >> Since Java7 we (or at least I) do not program that way anymore. You >> use try with resources. You only want the ResultSet, but to prevent a >> resource leak, you need to also create the Statement. That makes my >> hair stand up on the back of my neck. I don't know why it does so nasty things to your hair. You could wrap=20 your typical use cases easily in a (static) method that accepts a query=20 string and a Function which accepts a ResultSet and do the resource=20 cleanup in the static function. > You have 3 levels of resources: Connection, Statement, ResultSet. >=20 > You need 3 levels of try. It depends: you can get away with two levels if Statements do not live=20 much longer than ResultSets or if you only want to make sure resources=20 are released eventually because closing the Statement will implicitly=20 close the ResultSet as well. Kind regards robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/