BF [ 1874419 ] JDBC Statement not close in a finally block - fixed for AMenuStartItem
* organized imports for AMenuStartItem * minor: never call ADialog.error<sync> in "catch" block because you have to close statement & resultset in finally
This commit is contained in:
parent
b4414a594f
commit
6550a13cc4
|
@ -16,14 +16,22 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
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.apps.form.*;
|
import javax.swing.SwingUtilities;
|
||||||
import org.compiere.model.*;
|
import javax.swing.Timer;
|
||||||
import org.compiere.util.*;
|
|
||||||
|
import org.compiere.apps.form.FormFrame;
|
||||||
|
import org.compiere.model.MTask;
|
||||||
|
import org.compiere.util.CLogger;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.Ini;
|
||||||
|
import org.compiere.util.Msg;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,14 +121,17 @@ public class AMenuStartItem extends Thread implements ActionListener
|
||||||
SwingUtilities.invokeLater(m_resetPB);
|
SwingUtilities.invokeLater(m_resetPB);
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
SwingUtilities.invokeLater(m_updatePB);
|
SwingUtilities.invokeLater(m_updatePB);
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
String errmsg = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String sql = "SELECT * FROM AD_Menu WHERE AD_Menu_ID=?";
|
String sql = "SELECT * FROM AD_Menu WHERE AD_Menu_ID=?";
|
||||||
if (!m_isMenu)
|
if (!m_isMenu)
|
||||||
sql = "SELECT * FROM AD_WF_Node WHERE AD_WF_Node_ID=?";
|
sql = "SELECT * FROM AD_WF_Node WHERE AD_WF_Node_ID=?";
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
pstmt.setInt(1, m_ID);
|
pstmt.setInt(1, m_ID);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
|
|
||||||
SwingUtilities.invokeLater(m_updatePB);
|
SwingUtilities.invokeLater(m_updatePB);
|
||||||
if (rs.next()) // should only be one
|
if (rs.next()) // should only be one
|
||||||
|
@ -169,14 +180,20 @@ public class AMenuStartItem extends Thread implements ActionListener
|
||||||
} // for all records
|
} // for all records
|
||||||
|
|
||||||
SwingUtilities.invokeLater(m_updatePB);
|
SwingUtilities.invokeLater(m_updatePB);
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
log.log(Level.SEVERE, "ID=" + m_ID, e);
|
log.log(Level.SEVERE, "ID=" + m_ID, e);
|
||||||
ADialog.error(0, null, "Error", Msg.parseTranslation(Env.getCtx(), e.getMessage()));
|
errmsg = Msg.parseTranslation(Env.getCtx(), e.getMessage());
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null; pstmt = null;
|
||||||
|
}
|
||||||
|
// Show error if any
|
||||||
|
if (errmsg != null)
|
||||||
|
ADialog.error(0, null, "Error", errmsg);
|
||||||
|
|
||||||
try {Thread.sleep(1000);} // 1 sec
|
try {Thread.sleep(1000);} // 1 sec
|
||||||
catch (InterruptedException ie) {}
|
catch (InterruptedException ie) {}
|
||||||
|
@ -291,24 +308,12 @@ public class AMenuStartItem extends Thread implements ActionListener
|
||||||
SwingUtilities.invokeLater(m_updatePB); // 1
|
SwingUtilities.invokeLater(m_updatePB); // 1
|
||||||
// Get Command
|
// Get Command
|
||||||
MTask task = null;
|
MTask task = null;
|
||||||
String sql = "SELECT * FROM AD_Task WHERE AD_Task_ID=?";
|
if (AD_Task_ID > 0)
|
||||||
try
|
task = new MTask(Env.getCtx(), AD_Task_ID, null);
|
||||||
{
|
if (task.get_ID() != AD_Task_ID)
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
task = null;
|
||||||
pstmt.setInt(1, AD_Task_ID);
|
|
||||||
ResultSet rs = pstmt.executeQuery();
|
|
||||||
if (rs.next())
|
|
||||||
task = new MTask (Env.getCtx(), rs, null);
|
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, sql, e);
|
|
||||||
}
|
|
||||||
if (task == null)
|
if (task == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SwingUtilities.invokeLater(m_updatePB); // 2
|
SwingUtilities.invokeLater(m_updatePB); // 2
|
||||||
m_menu.getWindowManager().add(new ATask(m_name, task));
|
m_menu.getWindowManager().add(new ATask(m_name, task));
|
||||||
// ATask.start(m_name, task);
|
// ATask.start(m_name, task);
|
||||||
|
|
Loading…
Reference in New Issue