title: Can't delete row from a database
body: <p>I'm working at some school project and my job here is to make a delete button for that list view in Java FX, but the problem is that when i want to proceed that it shows me this error. I tried some solutions, but none of them worked. </p>
  
  <p>so here's the code </p>
  
  <pre><code>@FXML
  private void removeStudentOnClick(ActionEvent event) throws IOException, SQLException{
      ModelEditStudent student=(ModelEditStudent)tables.getSelectionModel().getSelectedItem();
      String sql="DELETE FROM student WHERE nr_indeksu=?";
  
      Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
      alert.setTitle("Usuwanie studenta");
      alert.setHeaderText(null);
      alert.setContentText("Czy na pewno chcesz usunąc tego studenta z listy?");
      Optional &lt;ButtonType&gt; action = alert.showAndWait();
  
      if(action.get() == ButtonType.OK){
  
      tables.getItems().removeAll(tables.getSelectionModel().getSelectedItem());  
  
      try{
  
          try (Connection myConn = ConnectionManager.getConnection()) {
           try (PreparedStatement st = myConn.prepareStatement(sql)) {
              st.setString(1, student.getNr_indeksu());
              st.executeUpdate();
          }
          myConn.close();
  
      }
  
      }catch (SQLException e){
          System.out.println(e);
      }
  }
  </code></pre>
  
  <p>and there's the error: </p>
  
  <pre><code> com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
   Cannot delete or update a parent row: a foreign key constraint fails
   (`wu`.`oceny`, CONSTRAINT `oceny_ibfk_3` FOREIGN KEY (`nr_indeksu`)
   REFERENCES `student` (`nr_indeksu`))
  </code></pre>
  
  <p>All the point of this operation is about selecting the row and removing from the database after pressing a button. By now it works only for the listview, but it doesn't remove records from the database. </p>
  
  <p>Anyone got an idea how make it work? </p>