
Hello, I've been working on the actionPerformed part of my java application that involves inserting a record into a 6-column table in my MS Access database table. I'm doing fine with retrieving the data with ResultSet, but I'm stuck on the actionPerformed events. The problem I'm having is that when the user clicks on the Add button, it's not doing anything (not even my JOptionPane). I'm stuck at this step. For simplicity, I am including only the add button listener and action events. I know I'm missing something, I just couldn't figure out where. Thanks in advance for your help. Below is part of my java code.
private class AddButtonListener implements ActionListener { public void actionPerformed (ActionEvent d) {
int donorNum = recordNum;
String name;
name = firstNameTextField.getText();
String lastName;
lastName = lastNameTextField.getText();
String middleI;
middleI = mITextField.getText();
String charity;
charity = comboBox.getSelectedItem().toString();
String pledge = pAmountTextField.getText();
double pl;
pl = Double.parseDouble(pledge);
record.setRecordNumber(donorNum);
record.setFirstName(name);
record.setLastName(lastName);
record.setMiddleInitial(middleI);
record.setCharity(charity);
record.setPledge(pl);
recNum.add(record.getRecordNumber());
lName.add(record.getLastName());
fName.add(record.getFirstName());
midI.add(record.getMiddleInitial());
lCharity.add(record.getCharity());
donAmount.add(record.getTotalPledge());
recordNum++;
try {
rs.moveToInsertRow();
rs.updateInt(1, recordNum);
rs.updateString(2, " " +name);
rs.updateString(3, " " + lastName);
rs.updateString(4, " " + middleI);
rs.updateString(5, " " + pledge);
rs.updateString(6, " " + charity);
rs.insertRow();
rs.moveToCurrentRow();
st.close();
rs.close();
st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "select * from DonorTable";
rs = st.executeQuery(sql);
rs.next();
firstNameTextField.setText(rs.getString("First_Name"));
lastNameTextField.setText(rs.getString("Last_Name"));
mITextField.setText(rs.getString("Middle_Initial"));
pAmountTextField.setText(rs.getString("Pledge_Amount"));
comboBox.setSelectedItem(rs.getString("Charity_Name"));
JOptionPane.showConfirmDialog(null, "Donor " + " " + name + " " + lastName + " " + middleI + " added");
}
catch (Exception ad) {
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.