-1

大家好,我必须更新SQLite数据库表中的行,我正在使用更新查询来更新行,但它不工作也不会抛出任何错误。

我的代码:

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

请建议我哪里错了。Thanks

4

3 回答 3

1

试试这个:

 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();
        }
    }
于 2012-10-10T07:32:11.303 回答
1

文档说:

public void execSQL (String sql)  

执行不是 SELECT 的单个 SQL 语句或任何其他返回数据的 SQL 语句。

因此,您需要execSQL()用于数据修改,例如:

•插入
•更新
•删除

rawQuery(String sql, String[] selectionArgs)

运行提供的 SQL 并返回结果集上的 Cursor。

rawQuery() 应该用于目的SELECT,它为 SELECT 查询返回 Cursor。

于 2012-10-10T12:40:36.060 回答
-1

最后我使用以下方法完成了这个execSQL

database.execSQL("UPDATE content SET  url2g = replace(url2g, '"
                + current_ip + "', '" + ip + "');");
于 2012-10-10T09:09:57.963 回答