HI. I'm having a java.sql.SQLException on my code. I don't understand why the resultset is closed in my try/catch block, since I put the close methods on the finally block.
Please help. I have searched the forum and I did what I could to research on this, but to no avail, i failed.
here is my code:
private void comboTBMonthItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
//code, title, gdebit, gcredit, tdebit, tcredit, rdebit, rcredit == 8 fields
//fund, daccount, debit, caccount, credit, wtax, dcfa, ccfa,wcfa
Connection conn = null, dConn = null;
Statement stmt = null, dStmt = null;
ResultSet rs = null, dRs = null;
String xCode = "", xFund = "";
double xDebit = 0, xCredit = 0;
if(evt.getStateChange() == java.awt.event.ItemEvent.SELECTED){
try{
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(accountingLogIn.connectInfo.getUrl(), accountingLogIn.connectInfo.getUser(),
accountingLogIn.connectInfo.getPasswd());
dConn = DriverManager.getConnection(accountingLogIn.connectInfo.getUrl(), accountingLogIn.connectInfo.getUser(),
accountingLogIn.connectInfo.getPasswd());
stmt = conn.createStatement();
stmt.executeUpdate("DELETE FROM accounting.trialbalance");
rs = stmt.executeQuery(
"SELECT daccount, caccount, debit, credit, wtax, LEFT(fund, 2) AS fund " +
"FROM accounting.jdv " +
"WHERE MONTH(jdvdate) = '"+ comboTBMonth.getSelectedItem() +"' " +
"AND YEAR(jdvdate) = '"+comboTBYear.getSelectedItem()+"'");
rs.beforeFirst();
int i = 0, x = 0;
while(rs.next()){
xFund = rs.getString("fund");
if(rs.getDouble("debit") != 0){
xCode = rs.getString("daccount");
xDebit = rs.getDouble("debit");
dStmt = dConn.createStatement();
dRs = dStmt.executeQuery(
"SELECT account, title, gfcredit, gfdebit, tfcredit, tfdebit, rfcredit, rfdebit " +
"FROM accounting.trialbalance");
dRs.last();
i = dRs.getRow();
//JOptionPane.showMessageDialog(this, i + " # row in trialbalance");
if(i == 0){
if(xFund.equals("GF")){
dStmt.executeUpdate(
"INSERT INTO accounting.trialbalance" +
"(account, gfdebit)" +
"VALUES('"+ rs.getString("daccount") +"', '"+ rs.getString("debit") +"')");
}
}
else{
// JOptionPane.showMessageDialog(this, i + " with contents");
dRs.beforeFirst();
int y = 0;
while(dRs.next()){
// JOptionPane.showMessageDialog(this, xFund);
if(xFund.equals("GF")){
// JOptionPane.showMessageDialog(this, dRs.getString("account") + " trial account");
if(dRs.getString("account").equals(rs.getString("daccount"))){
JOptionPane.showMessageDialog(this, "insert this");
dStmt.executeUpdate(
"UPDATE accounting.trialbalance " +
"SET gfdebit = '"+ (dRs.getDouble("gfdebit") + 5000) +"' " +
"WHERE account = '"+ rs.getString("daccount")+"'");
JOptionPane.showMessageDialog(this, "updated");
}
else{
dStmt.executeUpdate(
"INSERT INTO accounting.trialbalance" +
"(account, gfdebit)" +
"VALUES('"+ rs.getString("daccount") +"', '"+ rs.getString("debit") +"')");
}
}
}
}
}
}
displayTable(tableTB, "SELECT * FROM accounting.trialbalance ORDER BY account", scrollTB, getModelTableTB(), tbwidth);
}
catch(SQLException ex){
JOptionPane.showMessageDialog(this, ex + " A");
}
catch(ClassNotFoundException ex){
}
finally{
try{
dRs.close();
dRs = null;
dStmt.close();
dStmt = null;
rs.close();
rs = null;
stmt.close();
stmt = null;
conn.close();
conn = null;
}
catch(SQLException ex){
JOptionPane.showMessageDialog(this, ex + " B");
}
}
}
}