Reputation: 241
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...
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);}
}
Upvotes: 0
Views: 7987
Reputation: 1424
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..
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);}
}
Upvotes: 2