<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: Finally Closing of JDBC Resources	</title>
	<atom:link href="https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/</link>
	<description>Java/J2EE Software Development and Technology Discussion Blog</description>
	<lastBuildDate>Thu, 03 May 2012 04:10:58 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: Connecting to MS Access File via JDBC in 64-bit Java &#124; Down Home Country Coding With Scott Selikoff and Jeanne Boyarsky		</title>
		<link>https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/comment-page-1/#comment-4687</link>

		<dc:creator><![CDATA[Connecting to MS Access File via JDBC in 64-bit Java &#124; Down Home Country Coding With Scott Selikoff and Jeanne Boyarsky]]></dc:creator>
		<pubDate>Tue, 26 Jul 2011 21:58:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=3#comment-4687</guid>

					<description><![CDATA[[...] Sun JDK, then the driver will be available in the classpath automatically. Notice, I make sure to close my connection object in a finally block as all good JDBC developers know to [...]]]></description>
			<content:encoded><![CDATA[<p>[&#8230;] Sun JDK, then the driver will be available in the classpath automatically. Notice, I make sure to close my connection object in a finally block as all good JDBC developers know to [&#8230;]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jeanne Boyarsky		</title>
		<link>https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/comment-page-1/#comment-2487</link>

		<dc:creator><![CDATA[Jeanne Boyarsky]]></dc:creator>
		<pubDate>Thu, 03 Jun 2010 00:20:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=3#comment-2487</guid>

					<description><![CDATA[@Adam
Also, this assumes the database driver properly closes all resources when you close a connection.  Some older driver don&#039;t.]]></description>
			<content:encoded><![CDATA[<p>@Adam<br />
Also, this assumes the database driver properly closes all resources when you close a connection.  Some older driver don&#8217;t.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam		</title>
		<link>https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/comment-page-1/#comment-2486</link>

		<dc:creator><![CDATA[Adam]]></dc:creator>
		<pubDate>Wed, 02 Jun 2010 19:24:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=3#comment-2486</guid>

					<description><![CDATA[I also understand that the implementation supplied by various JDBC driver vendors have their own idiosyncrasies.  The JavaDoc seems vague, and there&#039;s no guarantee how the JDBC driver implements it.

So it seems the only way to actually guarantee that one&#039;s ResultSets, Statements and Connections get closed is by closing them yourself.

I&#039;m happy now, thanks.]]></description>
			<content:encoded><![CDATA[<p>I also understand that the implementation supplied by various JDBC driver vendors have their own idiosyncrasies.  The JavaDoc seems vague, and there&#8217;s no guarantee how the JDBC driver implements it.</p>
<p>So it seems the only way to actually guarantee that one&#8217;s ResultSets, Statements and Connections get closed is by closing them yourself.</p>
<p>I&#8217;m happy now, thanks.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Scott Selikoff		</title>
		<link>https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/comment-page-1/#comment-2485</link>

		<dc:creator><![CDATA[Scott Selikoff]]></dc:creator>
		<pubDate>Wed, 02 Jun 2010 19:13:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=3#comment-2485</guid>

					<description><![CDATA[@Adam

Actually closing connections in large enough systems isn&#039;t that common, especially with database pooling.  Connections can be used for a lot of transactions, and the statements/resultsets use resources while the connection is open.  Also, not all statements return result sets, such as statement.executeUpdate(), so you have to close it explicitly.

The general rule of thumb for JDBC development is explicitly close a resource (often through a finally block) as soon as it is not needed, or at least before the code does any other time consuming work such as calling other resources/connections.  Many JDBC performance problems are caused by developers forgetting to close resources properly.

Perhaps, if every connection had exactly one statement and every statement had exactly one result set, your argument would make sense, but in practice this is not the case.  In particular, such a system would not support transactions since the connection would be closed between any two calls.]]></description>
			<content:encoded><![CDATA[<p>@Adam</p>
<p>Actually closing connections in large enough systems isn&#8217;t that common, especially with database pooling.  Connections can be used for a lot of transactions, and the statements/resultsets use resources while the connection is open.  Also, not all statements return result sets, such as statement.executeUpdate(), so you have to close it explicitly.</p>
<p>The general rule of thumb for JDBC development is explicitly close a resource (often through a finally block) as soon as it is not needed, or at least before the code does any other time consuming work such as calling other resources/connections.  Many JDBC performance problems are caused by developers forgetting to close resources properly.</p>
<p>Perhaps, if every connection had exactly one statement and every statement had exactly one result set, your argument would make sense, but in practice this is not the case.  In particular, such a system would not support transactions since the connection would be closed between any two calls.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam		</title>
		<link>https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/comment-page-1/#comment-2484</link>

		<dc:creator><![CDATA[Adam]]></dc:creator>
		<pubDate>Wed, 02 Jun 2010 19:01:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=3#comment-2484</guid>

					<description><![CDATA[Understood.  I also supposed that if we close() the resource, then it can be reused immediately instead of waiting for the next garbage collection cycle.

One other question: Why would should we bother calling rs.close and stmt.close, when con.close is defined to automatically close those resources for us?

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#close%28%29
&#062; Releases this Connection object&#039;s database and JDBC resources immediately instead of waiting for them to be automatically released.

In fact, looking at this JavaDoc, it seems that Sun’s intention is for developers to rely on connections being closed during garbage collection, and that calling close() is only required for special cases.]]></description>
			<content:encoded><![CDATA[<p>Understood.  I also supposed that if we close() the resource, then it can be reused immediately instead of waiting for the next garbage collection cycle.</p>
<p>One other question: Why would should we bother calling rs.close and stmt.close, when con.close is defined to automatically close those resources for us?</p>
<p><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#close%28%29" rel="nofollow ugc">http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#close%28%29</a><br />
&gt; Releases this Connection object&#8217;s database and JDBC resources immediately instead of waiting for them to be automatically released.</p>
<p>In fact, looking at this JavaDoc, it seems that Sun’s intention is for developers to rely on connections being closed during garbage collection, and that calling close() is only required for special cases.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Scott Selikoff		</title>
		<link>https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/comment-page-1/#comment-2482</link>

		<dc:creator><![CDATA[Scott Selikoff]]></dc:creator>
		<pubDate>Wed, 02 Jun 2010 17:42:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=3#comment-2482</guid>

					<description><![CDATA[@Adam

You make the mistaken assumption that you can predict what the garbage collector is going to do.  In fact, the garbage collector isn&#039;t likely to run until the system is close to running out of memory.  If you never close any DB resources, you will run out of connections before you run out of memory.  Also, keep in mind the garbage collector doesn&#039;t have to run, nothing about the behavior is guaranteed and its far from the garbage collectors job to manage database resources.]]></description>
			<content:encoded><![CDATA[<p>@Adam</p>
<p>You make the mistaken assumption that you can predict what the garbage collector is going to do.  In fact, the garbage collector isn&#8217;t likely to run until the system is close to running out of memory.  If you never close any DB resources, you will run out of connections before you run out of memory.  Also, keep in mind the garbage collector doesn&#8217;t have to run, nothing about the behavior is guaranteed and its far from the garbage collectors job to manage database resources.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Adam		</title>
		<link>https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/comment-page-1/#comment-2481</link>

		<dc:creator><![CDATA[Adam]]></dc:creator>
		<pubDate>Wed, 02 Jun 2010 17:33:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=3#comment-2481</guid>

					<description><![CDATA[Why should we bother closing the DB resources?  They&#039;re all automatically closed when they&#039;re garbage collected.

http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html#close%28%29
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#close%28%29
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#close%28%29]]></description>
			<content:encoded><![CDATA[<p>Why should we bother closing the DB resources?  They&#8217;re all automatically closed when they&#8217;re garbage collected.</p>
<p><a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html#close%28%29" rel="nofollow ugc">http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.html#close%28%29</a><br />
<a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#close%28%29" rel="nofollow ugc">http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#close%28%29</a><br />
<a href="http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#close%28%29" rel="nofollow ugc">http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Connection.html#close%28%29</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Melloware		</title>
		<link>https://www.selikoff.net/2008/07/30/finally-closing-jdbc-resources/comment-page-1/#comment-4</link>

		<dc:creator><![CDATA[Melloware]]></dc:creator>
		<pubDate>Fri, 08 Aug 2008 14:20:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.selikoff.net/blog/?p=3#comment-4</guid>

					<description><![CDATA[Hey Scott,  it&#039;s Bud Lefkof I was a consultant at Octagon while you were there.  very cool site you have.  Just wanted to mention for this Blogpost you could use the excellent apache Commons DBUtils.  It has methods like DButisl.closeQuietly(rs); etc and cool DbUtils.commitAndCloseQuietly(conn); for doing mutliple things at once while handling NULLS and quelling SQLExceptions.

http://commons.apache.org/dbutils/

Melloware
http://www.melloware.com]]></description>
			<content:encoded><![CDATA[<p>Hey Scott,  it&#8217;s Bud Lefkof I was a consultant at Octagon while you were there.  very cool site you have.  Just wanted to mention for this Blogpost you could use the excellent apache Commons DBUtils.  It has methods like DButisl.closeQuietly(rs); etc and cool DbUtils.commitAndCloseQuietly(conn); for doing mutliple things at once while handling NULLS and quelling SQLExceptions.</p>
<p><a href="http://commons.apache.org/dbutils/" rel="nofollow ugc">http://commons.apache.org/dbutils/</a></p>
<p>Melloware<br />
<a href="http://www.melloware.com" rel="nofollow ugc">http://www.melloware.com</a></p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
