gpt4 book ai didi

Android SQLite多WHERE

转载 作者:太空宇宙 更新时间:2023-11-03 13:24:05 24 4
gpt4 key购买 nike

我一直在寻找它,但找不到我需要的东西。我在 android 中有一个 SQLite 表,我想知道 rawquery 将如何用于多个 WHERE 子句。我的意思是,我想知道一个表的所有记录以及其中两个列的值为 1 的所有列。

我该怎么做?

我试过:

String selectQuery = "SELECT  * FROM " + TABLE_NAME 
+ " WHERE " + KEY_ONE + " = " + String.valueOf(var1)
+ " AND WHERE " + KEY_TWO + " = " + String.valueOf(Var2);

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);

但它不起作用..

谢谢你的帮助:D

最佳答案

删除第二个WHERE:

+ " AND " + KEY_TWO + " = " + String.valueOf(Var2);

另请注意,字符串必须用撇号括起来:

String selectQuery = "SELECT  * FROM " + TABLE_NAME 
+ " WHERE " + KEY_ONE + " = '" + String.valueOf(var1)
+ "' AND " + KEY_TWO + " = '" + String.valueOf(Var2) + "'";

如果你使用这个增强的语法会更好:

String selectQuery = "SELECT  * FROM " + TABLE_NAME 
+ " WHERE " + KEY_ONE + " = ? AND " + KEY_TWO + " = ?";

SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, new String[]{String.valueOf(var1), String.valueOf(var2)});

关于Android SQLite多WHERE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22933764/

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