*BF [ 1874419 ] JDBC Statement not close in a finally block

*Organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-08 08:43:21 +00:00
parent 4d6fcf009b
commit 37bfc101b5
3 changed files with 54 additions and 41 deletions

View File

@ -16,13 +16,16 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere; package org.compiere;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.*; import org.compiere.model.MProductDownload;
import org.compiere.model.*; import org.compiere.print.PrintFormatUtil;
import org.compiere.print.*; import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
/** /**
* Migrate Data * Migrate Data
@ -65,10 +68,11 @@ public class MigrateData
+ "FROM M_Product " + "FROM M_Product "
+ "WHERE DownloadURL IS NOT NULL"; + "WHERE DownloadURL IS NOT NULL";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
int AD_Client_ID = rs.getInt(1); int AD_Client_ID = rs.getInt(1);
@ -97,24 +101,17 @@ public class MigrateData
else else
log.warning("Product Download not created M_Product_ID=" + M_Product_ID); log.warning("Product Download not created M_Product_ID=" + M_Product_ID);
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.log (Level.SEVERE, sql, e); log.log (Level.SEVERE, sql, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
} }
log.info("#" + count); log.info("#" + count);
} // release252c } // release252c

View File

@ -16,14 +16,33 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.apps; package org.compiere.apps;
import java.awt.event.*; import java.awt.event.ActionEvent;
import java.sql.*; import java.awt.event.ActionListener;
import java.util.logging.*; import java.sql.PreparedStatement;
import javax.swing.*; import java.sql.ResultSet;
import java.util.logging.Level;
import org.compiere.model.*; import javax.swing.JComponent;
import org.compiere.swing.*; import javax.swing.JPopupMenu;
import org.compiere.util.*;
import org.compiere.model.GridTab;
import org.compiere.model.MAsset;
import org.compiere.model.MBPartner;
import org.compiere.model.MCampaign;
import org.compiere.model.MInOut;
import org.compiere.model.MInvoice;
import org.compiere.model.MOrder;
import org.compiere.model.MPayment;
import org.compiere.model.MProduct;
import org.compiere.model.MProject;
import org.compiere.model.MQuery;
import org.compiere.model.MRMA;
import org.compiere.model.MUser;
import org.compiere.swing.CMenuItem;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/** /**
@ -113,10 +132,11 @@ public class ARequest implements ActionListener
+ " GROUP BY Processed " + " GROUP BY Processed "
+ "ORDER BY Processed DESC"; + "ORDER BY Processed DESC";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
if ("Y".equals(rs.getString(1))) if ("Y".equals(rs.getString(1)))
@ -124,9 +144,6 @@ public class ARequest implements ActionListener
else else
activeCount += rs.getInt(2); activeCount += rs.getInt(2);
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
@ -142,7 +159,12 @@ public class ARequest implements ActionListener
{ {
pstmt = null; pstmt = null;
} }
finally
{
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// //
if (activeCount > 0) if (activeCount > 0)
{ {

View File

@ -131,33 +131,27 @@ public abstract class Config
{ {
String sql = "SELECT WebContext FROM W_Store WHERE IsActive='Y'"; String sql = "SELECT WebContext FROM W_Store WHERE IsActive='Y'";
Statement stmt = null; Statement stmt = null;
ResultSet rs = null;
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
try try
{ {
stmt = con.createStatement(); stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(sql); rs = stmt.executeQuery(sql);
while (rs.next ()) while (rs.next ())
{ {
if (result.length() > 0) if (result.length() > 0)
result.append(","); result.append(",");
result.append(rs.getString(1)); result.append(rs.getString(1));
} }
rs.close ();
stmt.close ();
stmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
log.severe(e.toString()); log.severe(e.toString());
} }
try finally
{
if (stmt != null)
stmt.close ();
stmt = null;
}
catch (Exception e)
{ {
DB.close(rs, stmt);
rs = null;
stmt = null; stmt = null;
} }
return result.toString(); return result.toString();