Update data through java swing textfields in database.
String bname=jTextField11.getText();
int id=Integer.parseInt(jTextField12.getText());
String vname=jTextField13.getText();
String des=jTextArea2.getText();
int quan=Integer.parseInt(jTextField14.getText());
String pcat=jTextField15.getText();
int size=Integer.parseInt(jTextField16.getText());
String col=jTextField6.getText();
String pd=jTextField17.getText();
int sp=Integer.parseInt(jTextField18.getText());
int pc=Integer.parseInt(jTextField19.getText());
String pm=jTextField20.getText();
String dis=jTextField21.getText();
try
{
Connection c=new Connection();
java.sql.Connection con=c.connectit();
String sql="update stock set id=?,BrandName=?,VendorName=?,Description=?,Quantity=?,Category=?,Size=?,Color=?,PurchaseDate=?,PurchaseCost=?,SellingPrice=?,Product=?,Discount=? where id='"+id+"'";
PreparedStatement pst=con.prepareStatement(sql);
pst.setInt(1,id);
pst.setString(2,bname);
pst.setString(3,vname);
pst.setString(4,des);
pst.setInt(5,quan);
pst.setString(6,pcat);
pst.setInt(7,size);
pst.setString(8,col);
pst.setString(9,pd);
pst.setInt(10,pc);
pst.setInt(11,sp);
pst.setString(12,pm);
pst.setString(13,dis);
System.out.println("naveen");
int i= pst.executeUpdate();
if(i>0)
{
JOptionPane.showMessageDialog(null, "Update!!");
}
else
{
JOptionPane.showMessageDialog(null, "Wrong Data!!");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, e);
}
table();
settext1();