我想编写一个mySQL读取查询:
String query = "SELECT * FROM " + MY_TABLE
+ "where phone=" + phone + "AND isBloacked =1";
如何将其转换为方法语法?
Cursor cursor = getReadableDatabase().query(MY_TABLE,
new String[] { "phone" }, "phone", new String[] {}, null, null,
null);
您的第三个参数基本上是一个WHERE
子句,只是没有单词WHERE
。
public Cursor query (String table, String[] columns,
String selection, String[] selectionArgs,
String groupBy, String having, String orderBy, String limit)
从方法签名中可以找到selection
isWHERE
子句,并selectionArgs
允许您在字符串之外添加参数。
例如,对于您的查询,您可能想要执行以下操作:
Cursor cursor = getReadableDatabase().query(MY_TABLE,
new String[] { "phone" },
"phone = ? AND isBloacked = ?", new String[] { phone, "1" },
null, null, null);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句