user4773253
user4773253

Reputation:

Sqlite Update query syntax error

whenever I try to update details I get syntax error near nRating

 public void addRating(String name, String nDate, String nRating,
    String nComment)
{

SQLiteDatabase data = this.getWritableDatabase();

Cursor query = data.rawQuery("update Station Set " + " date " + " = "
    + nDate + "," + " rating " + nRating + "," + " comments "
    + nComment + " Where Stationname " + " = " + name, null);
query.close();

}

Upvotes: 2

Views: 87

Answers (2)

Daniel Nugent
Daniel Nugent

Reputation: 43322

The main issue of course is that you're missing the = as @Ranjith pointed out in the comments.

In addition, for an Update query you should use execSQL instead of rawQuery.

So, no need for a Cursor, and also close the database when you're done with it.

public void addRating(String name, String nDate, String nRating,
    String nComment)
{

   SQLiteDatabase data = this.getWritableDatabase();

   data.execSQL("update Station Set " + " date = "
    + nDate + "," + " rating = " + nRating + "," + " comments = "
    + nComment + " where Stationname = '" + name + "'" );

    data.close(); //close the database

}

Upvotes: 1

Psypher
Psypher

Reputation: 10829

You are missng "=" after rating and comments.

Change to as below:

Cursor query = data.rawQuery("Update Station Set " + " date " + " = " + nDate + "," + " rating = " + nRating + "," + " comments =" + nComment + " where Stationname " + " = " + name, null);

Upvotes: 0

Related Questions