嗨,有人能告訴我我的代碼有什麼問題嗎?它將包插入到我的數組列表中,但不會將其插入到我的數據庫中。每次用戶按下GUI上的添加按鈕時,下面發佈的代碼都會運行謝謝!從java GUI插入到數據庫中
//Add package
String time = new SimpleDateFormat("DD.MM.YYYY.HH.mm.ss").format(new java.util.Date());
String name = nameInputTF.getText();
String address = addressInputTF.getText();
String city = cityInput.getText();
String county = (String) countyCombo.getSelectedItem();
String contact = contactInput.getText();
String description = descriptionInput.getText();
double price = Double.parseDouble(priceInput.getText());
boolean prepaid = true || false;
id++;
//Adding packages to the list
packages.add(new Package(id, time, name, address, city, county, contact, description, price, prepaid));
//Method to display packages in the text field
displayList();
//Method to set all button visibility to false
buttonsFalse();
// Method that sets all text fields to blank
fieldsBlank();
try {
String sql = "INSERT INTO packages VALUES (?,?,?,?,?,?,?,?)";
statement = conn.prepareStatement(sql);
statement.setString(1, packIDInput.getText());
statement.setString(2, arrivedInput.getText());
statement.setString(3, nameInputTF.getText());
statement.setString(4, addressInputTF.getText());
statement.setString(5, contactInput.getText());
statement.setString(6, priceInput.getText());
statement.setString(7, countyCombo.getName());
statement.setString(8, cityInput.getText());
rs = statement.executeQuery();
} catch (SQLException ex) {
Logger.getLogger(A2ZTransit.class.getName()).log(Level.SEVERE, null, ex);
}
}
我很困惑,我在哪裏領域的空白? – Bryan
就在try catch塊之前調用fieldsBlank()方法,然後在try catch塊中獲得文本字段的值(例如nameInputTF.getText()),但我如何從fieldsBlank()方法的註釋中理解文本字段將是空的 –
不能相信我沒有發現!謝謝,但我拿出了方法調用,但它仍然沒有添加到DB – Bryan