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

*Organize imports
This commit is contained in:
Redhuan D. Oon 2008-02-09 11:08:45 +00:00
parent d515236a61
commit c4f0c7a1fa
1 changed files with 35 additions and 37 deletions

View File

@ -16,12 +16,22 @@
*****************************************************************************/ *****************************************************************************/
package org.compiere.model; package org.compiere.model;
import java.sql.*; import java.sql.PreparedStatement;
import java.text.*; import java.sql.ResultSet;
import java.util.*; import java.sql.Timestamp;
import java.util.logging.*; import java.text.SimpleDateFormat;
import org.apache.ecs.xhtml.*; import java.util.ArrayList;
import org.compiere.util.*; import java.util.Properties;
import java.util.logging.Level;
import org.apache.ecs.xhtml.b;
import org.apache.ecs.xhtml.hr;
import org.apache.ecs.xhtml.p;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Util;
/** /**
* Chat Model * Chat Model
@ -44,35 +54,29 @@ public class MChat extends X_CM_Chat
// //
String sql = "SELECT * FROM CM_Chat " String sql = "SELECT * FROM CM_Chat "
+ "WHERE AD_Client_ID=? AND AD_Table_ID=? ORDER BY Record_ID"; + "WHERE AD_Client_ID=? AND AD_Table_ID=? ORDER BY Record_ID";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, AD_Client_ID); pstmt.setInt (1, AD_Client_ID);
pstmt.setInt (2, AD_Table_ID); pstmt.setInt (2, AD_Table_ID);
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
list.add (new MChat (ctx, rs, null)); list.add (new MChat (ctx, rs, null));
} }
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;
}
// //
MChat[] retValue = new MChat[list.size()]; MChat[] retValue = new MChat[list.size()];
list.toArray (retValue); list.toArray (retValue);
@ -147,34 +151,28 @@ public class MChat extends X_CM_Chat
return m_entries; return m_entries;
ArrayList<MChatEntry> list = new ArrayList<MChatEntry>(); ArrayList<MChatEntry> list = new ArrayList<MChatEntry>();
String sql = "SELECT * FROM CM_ChatEntry WHERE CM_Chat_ID=? ORDER BY Created"; String sql = "SELECT * FROM CM_ChatEntry WHERE CM_Chat_ID=? ORDER BY Created";
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
ResultSet rs = null;
try try
{ {
pstmt = DB.prepareStatement (sql, null); pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, getCM_Chat_ID()); pstmt.setInt (1, getCM_Chat_ID());
ResultSet rs = pstmt.executeQuery (); rs = pstmt.executeQuery ();
while (rs.next ()) while (rs.next ())
{ {
list.add (new MChatEntry (getCtx(), rs, get_TrxName())); list.add (new MChatEntry (getCtx(), rs, get_TrxName()));
} }
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;
}
// //
m_entries = new MChatEntry[list.size ()]; m_entries = new MChatEntry[list.size ()];
list.toArray (m_entries); list.toArray (m_entries);