我试图通过我的对话框在我的数据库中插入 orderId(应该自动递增)和表号,但是当我返回 MySql 数据库时,orderId 或表号都没有存储。可能是什么问题呢?订单表具有以下属性:orderId、tableNum、numofGuests、itemIdFK、empIdFK。
private void orderButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try {
//Dialog box asking for the table number
String tableNumString = JOptionPane.showInputDialog(null,"What is the table number?",
"Your Password",JOptionPane.QUESTION_MESSAGE);
int tableNum = Integer.parseInt(tableNumString);
System.out.println(tableNum);
String query = "Insert into orders(orderId,tableNum) values(?,?)";
int order = 1;
ps = connection.prepareStatement(query);
ps.setInt(1, order);
ps.setInt(2, tableNum);
//switch to the next page after table number is inserted
CardLayout cl = (CardLayout)(mainpanel.getLayout());
cl.show(mainpanel,"card3");
} catch (SQLException | NumberFormatException ex) {}
}