gpt4 book ai didi

android - Sqlite 更新查询语法错误

转载 作者:搜寻专家 更新时间:2023-11-01 08:44:38 25 4
gpt4 key购买 nike

每当我尝试更新详细信息时,我都会在 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();

}

最佳答案

当然,主要问题是您缺少 =,正如@Ranjith 在评论中指出的那样。

此外,对于 Update 查询,您应该使用 execSQL 而不是 rawQuery

因此,不需要 Cursor,并且在完成后关闭数据库。

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

}

关于android - Sqlite 更新查询语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29658267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com