Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: Not closing connections and statements Date: Fri, 12 Aug 2016 21:44:58 -0400 Organization: Aioe.org NNTP Server Lines: 25 Message-ID: References: <87shuakxjq.fsf@Equus.decebal.nl> NNTP-Posting-Host: 7SK6yTFfqwlIPNBLl3l7Qg.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.2.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:35286 On 8/12/2016 3:01 PM, Martin Gregorie wrote: > On Fri, 12 Aug 2016 13:59:37 +0200, Cecil Westerhof wrote: >> As I understood it you should close your SQL connections and statements >> before quitting a program. How bad is this when that does not happen? >> > If you're going to use an SQL connection, it should be opened during > initialisation and closed as one of the last actions of the process: Yes and no. For a standalone Java SE application with single threaded database access then this strategy of open at start and close at finish works well. But for Java EE applications, Java SE application with multi threaded database access the strategy should be: - open just before it is needed for an operation - close as soon as operation is done > opening and closing DB connections is generally pretty slow. If that is a problem, then one use a connection pool. Arne