*BF [ 1874419 ] JDBC Statement not close in a finally block - fixed in 3 spots

*Organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-09 10:16:25 +00:00
parent 28c5fb4621
commit d515236a61
1 changed files with 31 additions and 46 deletions

View File

@ -16,10 +16,14 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.util.Properties;
import org.compiere.util.*; import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Msg;
/** /**
@ -52,12 +56,13 @@ public class M_Element extends X_AD_Element
return columnName; return columnName;
String retValue = columnName; String retValue = columnName;
String sql = "SELECT ColumnName FROM AD_Element WHERE UPPER(ColumnName)=?"; String sql = "SELECT ColumnName FROM AD_Element WHERE UPPER(ColumnName)=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setString (1, columnName.toUpperCase()); pstmt.setString (1, columnName.toUpperCase());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) if (rs.next ())
{ {
retValue = rs.getString(1); retValue = rs.getString(1);
@ -67,24 +72,17 @@ public class M_Element extends X_AD_Element
} }
else else
s_log.warning("No found: " + columnName); s_log.warning("No found: " + columnName);
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log (Level.SEVERE, columnName, e); s_log.log (Level.SEVERE, columnName, e);
} }
try finally
{ {
if (pstmt != null) DB.close(rs, pstmt);
pstmt.close (); rs = null; pstmt = null;
pstmt = null; }
}
catch (Exception e)
{
pstmt = null;
}
return retValue; return retValue;
} // getColumnName } // getColumnName
@ -112,12 +110,13 @@ public class M_Element extends X_AD_Element
return null; return null;
M_Element retValue = null; M_Element retValue = null;
String sql = "SELECT * FROM AD_Element WHERE UPPER(ColumnName)=?"; String sql = "SELECT * FROM AD_Element WHERE UPPER(ColumnName)=?";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setString (1, columnName.toUpperCase()); pstmt.setString (1, columnName.toUpperCase());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) if (rs.next ())
{ {
retValue = new M_Element (ctx, rs, trxName); retValue = new M_Element (ctx, rs, trxName);
@ -125,24 +124,16 @@ public class M_Element extends X_AD_Element
s_log.warning("Not unique: " + columnName s_log.warning("Not unique: " + columnName
+ " -> " + retValue + " - " + rs.getString("ColumnName")); + " -> " + retValue + " - " + rs.getString("ColumnName"));
} }
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log (Level.SEVERE, sql, e); s_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;
}
return retValue; return retValue;
} // get } // get
@ -163,31 +154,25 @@ public class M_Element extends X_AD_Element
+ "WHERE EXISTS (SELECT * FROM AD_Column c " + "WHERE EXISTS (SELECT * FROM AD_Column c "
+ "WHERE c.AD_Element_ID=e.AD_Element_ID AND c.AD_Column_ID=?)"; + "WHERE c.AD_Element_ID=e.AD_Element_ID AND c.AD_Column_ID=?)";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, trxName); pstmt = DB.prepareStatement (sql, trxName);
pstmt.setInt (1, AD_Column_ID); pstmt.setInt (1, AD_Column_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
if (rs.next ()) if (rs.next ())
retValue = new M_Element (ctx, rs, trxName); retValue = new M_Element (ctx, rs, trxName);
rs.close ();
pstmt.close ();
pstmt = null;
} }
catch (Exception e) catch (Exception e)
{ {
s_log.log (Level.SEVERE, sql, e); s_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;
} }
return retValue; return retValue;
} // get } // get