try
{
String rID=rid.getText();
String cID=cid.getText();
double Rcharge=Double.parseDouble(rc.getText());
double Mcharge=Double.parseDouble(mc.getText());
double total=Double.parseDouble(tot.getText());
double sum=Double.parseDouble(cash.getText());
double change=Double.parseDouble(bal.getText());
if(c_but.isSelected())
{
String sql ="INSERT INTO transactions(reservation_id,cus_id,room_charges,meal_charges,total_amount,cash,balance,payment_type) VALUES ('"+rID+"','"+cID+"','"+Rcharge+"','"+Mcharge+"','"+total+"','"+sum+"','"+change+"','CASH')" ;
pst=conn.prepareStatement(sql);
pst.execute();
}
else if(cre_but.isSelected())
{
String sql2 ="INSERT INTO transactions(reservation_id,cus_id,room_charges,meal_charges,total_amount,payment_type) VALUES ('"+rID+"','"+cID+"','"+Rcharge+"','"+Mcharge+"','"+total+"','CRED')" ;
pst=conn.prepareStatement(sql2);
pst.execute();
}
}
catch(Exception e){
}
我创建了上面的代码来将数据插入到 mysql 数据库中。
c_but
和 cre_but
是单选按钮。
没有语法错误。
但是我从界面添加的值不会出现在表格中。有人能找到错误吗?
最佳答案
我认为抛出了一些异常,但由于空的 catch block ,它是不可见的,因此它的行为就像程序成功完成一样。 像这样重写 catch block :
catch(Exception e){
throw e;
}
您可能会明白问题所在。
关于java - 通过java swing向数据库插入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36382399/