0

I'm trying to remove a row based on the id but i keep getting a NullPointerException.

My code:

public void removePatientsFromDatabase(int id) {
    String removeSql = "DELETE FROM patienten WHERE idPatient id = idn";
    try (Connection con = sql2o.open()) {
        con.createQuery(removeSql)
                .addParameter("idn", id)
                .executeUpdate();
    }
}

The error:

enter image description here

The database:

enter image description here

Skupaj
  • 83
  • 8
  • 1
    Go to line 133 of Query.java and check the values of any objects where you're trying to access methods or fields. – ManoDestra May 26 '16 at 13:30
  • I know what a NullPointerException is, how do i go to Query.java since it's not a class i made – Skupaj May 26 '16 at 13:33
  • Follow the stack trace down until you hit one of your classes. I didn't look closely at the package names above. You should know which one is yours. Perhaps GUI.java at line 333? Or the ones above that? DataLayer.java at line 56? And you're not catching exceptions above either. And the SQL has an error. – ManoDestra May 26 '16 at 13:38

2 Answers2

2

you need add : before your parameter. Try:

DELETE FROM patienten WHERE idPatient= :idn
andy
  • 1,316
  • 9
  • 23
1

You have a redundant id var in your query. Try:

DELETE FROM patienten WHERE idPatient= :idn
apomene
  • 13,898
  • 9
  • 41
  • 64