i have a program that has a database in access and i want to update data but when i click on update button on my frame nothing happens no error no exception and no work.
here is my code
bUpdate=new JButton("Update");
bUpdate.setBounds(275,600,100,50);
c.add(bUpdate);
bUpdate.addActionListener(this);
public void actionPerformed(ActionEvent ae){
Object o=ae.getSource();
if(o.equals(bUpdate)){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);DBQ=fddata.mdb");
PreparedStatement st=con.prepareStatement("update accthld set AName=?,DateOfOpeng=?,Address=?,ContactNo=?,TotalBalance=? where AccountNo=?");
st.setString(1,tAccountNo.getText());
st.setString(2,tAName.getText());
st.setString(3,tDateofOpng.getText());
st.setString(4,tAddress.getText());
st.setString(5,tContactNo.getText());
st.setInt(6,Integer.parseInt(tTotalBalance.getText())) int a=mAccthld.getRowCount();
for (int i = 0; i<a; i++)
mAccthld.removeRow(0);
fillTable();
int n= st.executeUpdate(); if(n>0)
{
JOptionPane.showMessageDialog(c,"updated");
}
con.close();
}
catch(Exception ex){
ex.printStackTrace();
}
}
and code for method filltable is
void fillTable(){
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:DRIVER=Microsoft Access Driver (*.mdb);DBQ=fddata.mdb");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("Select * from accthld");
while(rs.next())
{
Vector v=new Vector();
v.add(rs.getString(1));
v.add(rs.getString(2));
v.add(DateToString(rs.getDate(3)));
v.add(rs.getString(4));
v.add(rs.getString(5));
v.add(rs.getInt(6));
mAccthld.addRow(v);
}
con.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
}