2017-07-18 28 views
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{ 
} 
} 
+1

FROMキーワードを追加するのを忘れ考えます'execUpdate'のために。 –

+1

あなたのコードをデバッグし、それが狭くなる場所を見てみてください – JeffUK

+0

omg、ありがとうございます。それは愚かな間違いだった –

答えて

2

を達成するために使用しています方法である私は、あなたが、 `execAction`のコードはありません表示SQL

String st = "DELETE FROM CUSTOMER WHERE id = '"+ mID +"'" ; 
関連する問題