我想通過我的對話框在我的數據庫中插入orderId(應該自動遞增)和表號,但是當我回到MySql數據庫時,既沒有存儲orderId也沒有表號。可能是什麼問題呢? orders表具有屬性: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) {}
}
您將整個事物放在try/catch結構中。你可能會掩蓋一些錯誤。嘗試在異常塊中打印堆棧跟蹤以查看是否有任何事情正在進行。 – 2013-04-24 23:38:18