0

I am developing java application in netbeans. I connected database sqlite and it works perfectly. Now, i am trying to delete a field in database:

public void delete(){
    dbo.openConnection();
    String sqlCommand = "DELETE FROM restaurante WHERE id_restaurante = " + this.id_restaurante;
    System.out.println(sqlCommand);
    dbo.executeSQL(sqlCommand);
    dbo.closeConnection();
}

When i execute this method, i get this error:

DELETE FROM restaurante WHERE id_restaurante = 4
ERRO null

...and the field doesn't delete in database.

If i copy this line: DELETE FROM restaurante WHERE id_restaurante = 4 and try delete in sqlite manager (add-on firefox), works perfectly.

Any ideas?

apolo90
  • 57
  • 1
  • 9

3 Answers3

0

Maybe try this:

String sqlCommand = "DELETE FROM `restaurante` WHERE `id_restaurante` = " + this.id_restaurante;
0x6C38
  • 6,796
  • 4
  • 35
  • 47
0

What is ERRO null ??? Is it a stack trace uncomplete or something you write yourself ? I guess for the second solution, something is wrong in the method

dbo.executeSQL(sqlCommand);

Debug or add log.
Check that :

  1. Connection is correctly open.
  2. Check that there is no null pointer in the method abobe. I am nearly sure that is the problem.
  3. Check that you have the right to delete with the connection in your program.
mki
  • 635
  • 3
  • 10
0

This should work

String sqlCommand = "DELETE FROM restaurante WHERE id_restaurante = '" +id_restaurante+"'";
mohamed nur
  • 331
  • 1
  • 15