BF [ 1874419 ] JDBC Statement not close in a finally block - fixed for MQuery

This commit is contained in:
teo_sarca 2008-02-09 12:34:11 +00:00
parent 76ac6d191f
commit 4da0bc719d
1 changed files with 25 additions and 24 deletions

View File

@ -16,11 +16,21 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.io.*; import java.io.Serializable;
import java.sql.*; import java.sql.PreparedStatement;
import java.util.*; import java.sql.ResultSet;
import java.util.logging.*; import java.sql.SQLException;
import org.compiere.util.*; import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Properties;
import java.util.logging.Level;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.ValueNamePair;
/** /**
* Query Descriptor. * Query Descriptor.
@ -47,22 +57,8 @@ public class MQuery implements Serializable
query.addRestriction(TableName + ".AD_PInstance_ID=" + AD_PInstance_ID); query.addRestriction(TableName + ".AD_PInstance_ID=" + AD_PInstance_ID);
// How many rows do we have? // How many rows do we have?
int rows = 0;
String SQL = "SELECT COUNT(*) FROM AD_PInstance_Para WHERE AD_PInstance_ID=?"; String SQL = "SELECT COUNT(*) FROM AD_PInstance_Para WHERE AD_PInstance_ID=?";
try int rows = DB.getSQLValue(null, SQL, AD_PInstance_ID);
{
PreparedStatement pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, AD_PInstance_ID);
ResultSet rs = pstmt.executeQuery();
if (rs.next())
rows = rs.getInt(1);
rs.close();
pstmt.close();
}
catch (SQLException e1)
{
s_log.log(Level.SEVERE, SQL, e1);
}
if (rows < 1) if (rows < 1)
return query; return query;
@ -90,13 +86,15 @@ public class MQuery implements Serializable
+ " AND pp.AD_Process_Para_ID=ppt.AD_Process_Para_ID" + " AND pp.AD_Process_Para_ID=ppt.AD_Process_Para_ID"
+ " AND ip.AD_PInstance_ID=?" + " AND ip.AD_PInstance_ID=?"
+ " AND ppt.AD_Language=?"; + " AND ppt.AD_Language=?";
PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
PreparedStatement pstmt = DB.prepareStatement(SQL, null); pstmt = DB.prepareStatement(SQL, null);
pstmt.setInt(1, AD_PInstance_ID); pstmt.setInt(1, AD_PInstance_ID);
if (trl) if (trl)
pstmt.setString(2, Env.getAD_Language(ctx)); pstmt.setString(2, Env.getAD_Language(ctx));
ResultSet rs = pstmt.executeQuery(); rs = pstmt.executeQuery();
// all records // all records
for (int row = 0; rs.next(); row++) for (int row = 0; rs.next(); row++)
{ {
@ -192,13 +190,16 @@ public class MQuery implements Serializable
} }
} }
} }
rs.close();
pstmt.close();
} }
catch (SQLException e2) catch (SQLException e2)
{ {
s_log.log(Level.SEVERE, SQL, e2); s_log.log(Level.SEVERE, SQL, e2);
} }
finally
{
DB.close(rs, pstmt);
rs = null; pstmt = null;
}
s_log.info(query.toString()); s_log.info(query.toString());
return query; return query;
} // get } // get