You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-dev@jakarta.apache.org by pi...@apache.org on 2005/02/17 01:41:37 UTC
cvs commit: jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql QueryTagSupport.java
pierred 2005/02/16 16:41:37
Modified: standard/src/org/apache/taglibs/standard/tag/common/sql
QueryTagSupport.java
Log:
Patch from Dhiru Pandey for bug #17388
This is needed because in the current implementation, if an error occurs
before the preparedStatement is closed, then the closing of the
preparedStatement would depend on the implementation of finalize() for
the PreparedStatement class which should be called when that object is
GCed (Garbage Collected). This is not a good practice since:
a) we should not depend on the implementation of the finalize() method
in PreparedStatement
b) the invocation of the finalize() method is not guaranteed by the JVM.
So even if finalize() does call close(), there is no guarantee
that finalize() itself will be called when this object is GCed
and we may continue to see memory leaks and resource leaks
as reported in Bug 17388 (Result set created in query tag is never
released + update tag)
Revision Changes Path
1.40 +10 -2 jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java
Index: QueryTagSupport.java
===================================================================
RCS file: /home/cvs/jakarta-taglibs/standard/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- QueryTagSupport.java 28 Feb 2004 01:01:45 -0000 1.39
+++ QueryTagSupport.java 17 Feb 2005 00:41:36 -0000 1.40
@@ -209,15 +209,23 @@
* value for isLimitedByMaxRows(); there's no way to check
* if it was from the ResultSet.
*/
+ PreparedStatement ps = null;
try {
- PreparedStatement ps = conn.prepareStatement(sqlStatement);
+ ps = conn.prepareStatement(sqlStatement);
setParameters(ps, parameters);
ResultSet rs = ps.executeQuery();
result = new ResultImpl(rs, startRow, maxRows);
- ps.close();
}
catch (Throwable e) {
throw new JspException(sqlStatement + ": " + e.getMessage(), e);
+ } finally {
+ if (ps != null) {
+ try {
+ ps.close();
+ } catch (SQLException sqe) {
+ throw new JspException(sqe.getMessage(), sqe);
+ }
+ }
}
pageContext.setAttribute(var, result, scope);
return EVAL_PAGE;
---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-dev-help@jakarta.apache.org