我想编写一个 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
是 WHERE
子句,selectionArgs
允许您在字符串之外添加参数。
例如,对于您的查询,您可能需要执行以下操作:
Cursor cursor = getReadableDatabase().query(MY_TABLE,
new String[] { "phone" },
"phone = ? AND isBloacked = ?", new String[] { phone, "1" },
null, null, null);
关于java - 如何将 'where' mySQL 查询转换为方法语法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27368418/