This is the code I used to insert data from jtable to database:
for(int i=1 ; i <= table.getRowCount() ; i++){
String productid = table.getValueAt(i, 0).toString();
String name = table.getValueAt(i, 1).toString();
String quantity = table.getValueAt(i, 2).toString();
String totalprice = table.getValueAt(i, 4).toString();
try {
String query = "insert into sales (productid,customerid,name,quantity,discount,totalprice,paymentmethod) values (?,?,?,?,?,?,?)";
pst = con.prepareStatement(query);
pst.setString(1, productid);
pst.setString(2, customerid.getText());
pst.setString(3, name);
pst.setString(4, quantity);
pst.setString(5, discount.getText()+"%");
pst.setString(6, String.valueOf(totalprice));
pst.setString(7, paymethod.getSelectedItem().toString());
pst.execute();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
and when I click the button save it gives me an error.
Aucun commentaire:
Enregistrer un commentaire