BF [ 1874419 ] JDBC Statement not close in a finally block
This commit is contained in:
parent
3e0dda6632
commit
f2e82970e0
|
@ -1807,10 +1807,12 @@ public class GridTable extends AbstractTableModel
|
||||||
log.fine("Reading ... " + whereClause);
|
log.fine("Reading ... " + whereClause);
|
||||||
StringBuffer refreshSQL = new StringBuffer(m_SQL_Select)
|
StringBuffer refreshSQL = new StringBuffer(m_SQL_Select)
|
||||||
.append(" WHERE ").append(whereClause);
|
.append(" WHERE ").append(whereClause);
|
||||||
PreparedStatement pstmt = DB.prepareStatement(refreshSQL.toString(), null);
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ResultSet rs = pstmt.executeQuery();
|
pstmt = DB.prepareStatement(refreshSQL.toString(), null);
|
||||||
|
rs = pstmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
{
|
{
|
||||||
Object[] rowDataDB = readData(rs);
|
Object[] rowDataDB = readData(rs);
|
||||||
|
@ -1818,27 +1820,20 @@ public class GridTable extends AbstractTableModel
|
||||||
m_buffer.set(sort.index, rowDataDB);
|
m_buffer.set(sort.index, rowDataDB);
|
||||||
fireTableRowsUpdated(m_rowChanged, m_rowChanged);
|
fireTableRowsUpdated(m_rowChanged, m_rowChanged);
|
||||||
}
|
}
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
try
|
|
||||||
{
|
|
||||||
if (pstmt != null)
|
|
||||||
pstmt.close ();
|
|
||||||
pstmt = null;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
String msg = "SaveError";
|
String msg = "SaveError";
|
||||||
log.log(Level.SEVERE, refreshSQL.toString(), e);
|
log.log(Level.SEVERE, refreshSQL.toString(), e);
|
||||||
fireDataStatusEEvent(msg, e.getLocalizedMessage(), true);
|
fireDataStatusEEvent(msg, e.getLocalizedMessage(), true);
|
||||||
return SAVE_ERROR;
|
return SAVE_ERROR;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null;
|
||||||
|
pstmt = null;
|
||||||
|
}
|
||||||
|
|
||||||
// everything ok
|
// everything ok
|
||||||
m_rowData = null;
|
m_rowData = null;
|
||||||
|
@ -2262,12 +2257,12 @@ public class GridTable extends AbstractTableModel
|
||||||
StringBuffer sql = new StringBuffer("DELETE ");
|
StringBuffer sql = new StringBuffer("DELETE ");
|
||||||
sql.append(m_tableName).append(" WHERE ").append(getWhereClause(rowData));
|
sql.append(m_tableName).append(" WHERE ").append(getWhereClause(rowData));
|
||||||
int no = 0;
|
int no = 0;
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement pstmt = DB.prepareStatement (sql.toString(),
|
pstmt = DB.prepareStatement (sql.toString(),
|
||||||
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, null);
|
ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, null);
|
||||||
no = pstmt.executeUpdate();
|
no = pstmt.executeUpdate();
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
|
@ -2278,6 +2273,11 @@ public class GridTable extends AbstractTableModel
|
||||||
fireDataStatusEEvent(msg, e.getLocalizedMessage(), true);
|
fireDataStatusEEvent(msg, e.getLocalizedMessage(), true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(pstmt);
|
||||||
|
pstmt = null;
|
||||||
|
}
|
||||||
// Check Result
|
// Check Result
|
||||||
if (no != 1)
|
if (no != 1)
|
||||||
{
|
{
|
||||||
|
@ -2387,15 +2387,15 @@ public class GridTable extends AbstractTableModel
|
||||||
String sql = m_SQL_Select + " WHERE " + where;
|
String sql = m_SQL_Select + " WHERE " + where;
|
||||||
sort = (MSort)m_sort.get(row);
|
sort = (MSort)m_sort.get(row);
|
||||||
Object[] rowDataDB = null;
|
Object[] rowDataDB = null;
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement pstmt = DB.prepareStatement(sql, null);
|
pstmt = DB.prepareStatement(sql, null);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
// only one row
|
// only one row
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
rowDataDB = readData(rs);
|
rowDataDB = readData(rs);
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
|
@ -2404,6 +2404,12 @@ public class GridTable extends AbstractTableModel
|
||||||
fireDataStatusEEvent("RefreshError", sql, true);
|
fireDataStatusEEvent("RefreshError", sql, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
rs = null;
|
||||||
|
pstmt = null;
|
||||||
|
}
|
||||||
|
|
||||||
// update buffer
|
// update buffer
|
||||||
m_buffer.set(sort.index, rowDataDB);
|
m_buffer.set(sort.index, rowDataDB);
|
||||||
|
@ -2892,15 +2898,15 @@ public class GridTable extends AbstractTableModel
|
||||||
// log.config( "MTable Loader.open");
|
// log.config( "MTable Loader.open");
|
||||||
// Get Number of Rows
|
// Get Number of Rows
|
||||||
int rows = 0;
|
int rows = 0;
|
||||||
|
PreparedStatement pstmt = null;
|
||||||
|
ResultSet rs = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PreparedStatement pstmt = DB.prepareStatement(m_SQL_Count, null);
|
pstmt = DB.prepareStatement(m_SQL_Count, null);
|
||||||
setParameter (pstmt, true);
|
setParameter (pstmt, true);
|
||||||
ResultSet rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
if (rs.next())
|
if (rs.next())
|
||||||
rows = rs.getInt(1);
|
rows = rs.getInt(1);
|
||||||
rs.close();
|
|
||||||
pstmt.close();
|
|
||||||
}
|
}
|
||||||
catch (SQLException e0)
|
catch (SQLException e0)
|
||||||
{
|
{
|
||||||
|
@ -2911,6 +2917,10 @@ public class GridTable extends AbstractTableModel
|
||||||
log.log(Level.SEVERE, "Count SQL=" + m_SQL_Count, e0);
|
log.log(Level.SEVERE, "Count SQL=" + m_SQL_Count, e0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DB.close(rs, pstmt);
|
||||||
|
}
|
||||||
StringBuffer info = new StringBuffer("Rows=");
|
StringBuffer info = new StringBuffer("Rows=");
|
||||||
info.append(rows);
|
info.append(rows);
|
||||||
if (rows == 0)
|
if (rows == 0)
|
||||||
|
@ -2945,17 +2955,7 @@ public class GridTable extends AbstractTableModel
|
||||||
private void close()
|
private void close()
|
||||||
{
|
{
|
||||||
// log.config( "MTable Loader.close");
|
// log.config( "MTable Loader.close");
|
||||||
try
|
DB.close(m_rs, m_pstmt);
|
||||||
{
|
|
||||||
if (m_rs != null)
|
|
||||||
m_rs.close();
|
|
||||||
if (m_pstmt != null)
|
|
||||||
m_pstmt.close();
|
|
||||||
}
|
|
||||||
catch (SQLException e)
|
|
||||||
{
|
|
||||||
log.log(Level.SEVERE, "closeRS", e);
|
|
||||||
}
|
|
||||||
m_rs = null;
|
m_rs = null;
|
||||||
m_pstmt = null;
|
m_pstmt = null;
|
||||||
} // close
|
} // close
|
||||||
|
|
Loading…
Reference in New Issue