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();
			 }
                 	
           }

1) What else can be expected when you first call fillTable(); (line 22) and only after that you execute update statement int n= st.executeUpdate(); (line 23)
2) Ever heard of code duplication? (You are setting up DB connection in two different places, if not more since I do not have access to whole application. Create a method that will return you a connection, use connection fro executing what ever query you need and then close it. See example in JSP section)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.