Not deleting from the Database the data I want

Asked

Viewed 42 times

-2

I have this code that supposedly erases the date I put in the method from Database. But it’s not deleting from Database and I don’t understand why. Here is the information :

    public void deleteRowWhitDate(String date){
    String query = "DELETE FROM " + TABLE_NAME+ " WHERE "+ COL_4 + " = " + date ;
    database.execSQL(query);
}

I’m sure Database contains the date I date.

      public static final String TABLE_NAME = "Exames_table";
    public static final String COL_4 = "DIA";

Making the

Log.d("debug",query);

I obtained :

DELETE FROM Exames_table WHERE DIA = 30-07-2017

  • Debug the operation and get the final string of the query variable and try to run directly in the database.

  • 3

    Makes Log.d("debug", query); before she is executed in database.execSQL(query); and say what you have

  • What type you used when you created the "DIA" column in the table (Text, INTEGER, etc.) and says an example of value that you pass in the String date.

  • Example : 30-07-2017 , I used Text type

  • @Isac gave this DELETE FROM Exames_table WHERE DIA = 30-07-2017

  • @Pedrogouveia believe that the sql syntax is wrong! Try to run this sql in some DBMS. Possibly the date is not recorded this way (30-07-2017) in the bank. And if it is necessary to put the ' character to work. Example: DELETE FROM Exames_table WHERE DIA = '30-07-2017'

  • @Karanpereira Yes put ' helped already worked thanks !

Show 2 more comments

1 answer

1


If you set the column to TEXT, then the problem is that it lacked plics (') in the comparison parameter of your SQL query. It should be yes:

String query = "DELETE FROM " + TABLE_NAME+ " WHERE "+ COL_4 + " = '" + date + "'";

Browser other questions tagged

You are not signed in. Login or sign up in order to post.