大家好,我必须更新SQLite
数据库表中的行,我正在使用更新查询来更新行,但它不工作也不会抛出任何错误。
我的代码:
database.rawQuery(" UPDATE content SET url2g = replace(url2g, '"
+ current_ip + "', '" + ip + "');", null);
请建议我哪里错了。Thanks
大家好,我必须更新SQLite
数据库表中的行,我正在使用更新查询来更新行,但它不工作也不会抛出任何错误。
我的代码:
database.rawQuery(" UPDATE content SET url2g = replace(url2g, '"
+ current_ip + "', '" + ip + "');", null);
请建议我哪里错了。Thanks
试试这个:
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();
}
}
文档说:
public void execSQL (String sql)
执行不是 SELECT 的单个 SQL 语句或任何其他返回数据的 SQL 语句。
因此,您需要execSQL()
用于数据修改,例如:
•插入
•更新
•删除
rawQuery(String sql, String[] selectionArgs)
运行提供的 SQL 并返回结果集上的 Cursor。
rawQuery()
应该用于目的SELECT
,它为 SELECT 查询返回 Cursor。
最后我使用以下方法完成了这个execSQL
database.execSQL("UPDATE content SET url2g = replace(url2g, '"
+ current_ip + "', '" + ip + "');");