Question

I have Jtable and when I click (select) it goes to textfield. What I want is when I edit in the textfield it also change in database. However everything work only that my edition data have changed every other data. pls look at the picture. After edit I click OK then click refresh all data become like that...attachment

here is my OK button code:

 private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try{
        String url = "jdbc:odbc:mydata";
        Connection conn = DriverManager.getConnection(url,"","");
    String value1=tfSupName1.getText();
    String value2=tfType1.getText();
    String value3=tfStock1.getText();

    String sql="UPDATE User set SupplierName='"+value1+"' ,MarbleType='"+value2+"' ,InStock='"+value3+"'";

    pst=conn.prepareStatement(sql);
   pst.execute();
    }catch(Exception e){JOptionPane.showMessageDialog(null,e);}
}
Was it helpful?

Solution

I Think In your Database table have Supplier_id column as Integer...

Add Supplier id in Your form...

When click on jtable supplier Id also displayed in textfield..

enter image description here like this..

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try{
        String url = "jdbc:odbc:mydata";
        Connection conn = DriverManager.getConnection(url,"","");
        String value1=tfSupName1.getText();
        String value2=tfType1.getText();
        String value3=tfStock1.getText();
        String sql="UPDATE User set SupplierName='"+value1+"' ,MarbleType='"+value2+"' ,InStock='"+value3+"' Where Supplier_id=1";
        pst=conn.prepareStatement(sql);
        pst.execute();
    }
    catch(Exception e){JOptionPane.showMessageDialog(null,e);}

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top