1
データベースで単純な削除操作を実行したいが、プログラムがビジー状態になり、応答が停止する。私はエラーが表示されていないので、何が起こっているのか分かりません。ここデータベースの削除操作
private void deleteCustomer(ActionEvent event) {
String mName = name.getText();
String mID = id.getText();
Boolean flag = mName.isEmpty() || mID.isEmpty();
if(flag){
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setHeaderText(null);
alert.setContentText("Please Enter All Fields.");
alert.showAndWait();
return;
}
String st = "DELETE CUSTOMER WHERE id = '"+ mID +"'" ;
System.out.println(st);
if(handler.execAction(st)){
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setHeaderText(null);
alert.setContentText("Deleted");
alert.showAndWait();
//return;
}else{
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setHeaderText(null);
alert.setContentText("Error Occured");
alert.showAndWait();
}
}
は、私はタスク
public boolean execUpdate(String query){
try {
stmt = conn.createStatement();
//stmt.executeUpdate(query);
if(stmt.executeUpdate(query) == 1){
// JOptionPane.showMessageDialog(null, "data " + message);
System.out.println("data deleted succefully!!");
}
return true;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "error: "+ e.getMessage(), "error occoured", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception at execQuery: dataHandler" + e.getLocalizedMessage());
return false;
}finally{
}
public boolean execAction(String query){
try {
stmt = conn.createStatement();
stmt.execute(query);
return true;
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "error: "+ e.getMessage(), "error occoured", JOptionPane.ERROR_MESSAGE);
System.out.println("Exception at execQuery: dataHandler" + e.getLocalizedMessage());
return false;
}finally{
}
}
を
FROM
キーワードを追加するのを忘れ考えます'execUpdate'のために。 –あなたのコードをデバッグし、それが狭くなる場所を見てみてください – JeffUK
omg、ありがとうございます。それは愚かな間違いだった –