-1

HI all i have to update row in SQLitedatabase table,i'm using update query for update row but it's not working also not throw any error.

MY CODE:

database.rawQuery(" UPDATE content SET  url2g = replace(url2g, '"
                + current_ip + "', '" + ip + "');", null);

please suggest me where i'm wrong.Thanks

Dilip
  • 2,271
  • 5
  • 32
  • 52
  • not any error code execute successfully – Dilip Oct 10 '12 at 08:11
  • Could [this](http://stackoverflow.com/questions/5575211/android-sqlite-update-not-working) or [this](http://stackoverflow.com/questions/8119589/update-function-in-android-sqlite-is-not-working) link be helpful? I am sure many others have tackled this problem. If you can be more specific and perhaps provide some error log information, we can find an answer for you. – Michal Oct 10 '12 at 07:26

3 Answers3

1

Try this:

 public void updatemember(String id,String password,String status) {
        // TODO Auto-generated method stub


        ContentValues dataToInsert = new ContentValues();
        dataToInsert.put("status", status);
        dataToInsert.put("password", password);

        String where= " id = " + "\"" + id + "\"";

        try {

            db.update(TABLE_NAME, dataToInsert, where, null);

        } catch (Exception e) {


            String error = e.getMessage().toString();
        }
    }
Anklet.
  • 479
  • 3
  • 14
  • thanks but i want to execute above sql statement for update row...any idea please suggest me – Dilip Oct 10 '12 at 09:02
1

Documentation says:

public void execSQL (String sql)  

Execute a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.

So you need to use execSQL() for data modification like:

•INSERT
•UPDATE
•DELETE

rawQuery(String sql, String[] selectionArgs)

Runs the provided SQL and returns a Cursor over the result set.

The rawQuery() should be used for SELECT purpose, it returns Cursor for SELECT queries.

Yaqub Ahmad
  • 27,569
  • 23
  • 102
  • 149
-1

Finally i done this using following execSQL

database.execSQL("UPDATE content SET  url2g = replace(url2g, '"
                + current_ip + "', '" + ip + "');");
Dilip
  • 2,271
  • 5
  • 32
  • 52