我试图获取标题等于我传入的字符串的行ID。
我对语法非常不满,我一直在浏览这个网站,试图找到Eclipse会喜欢的例子。通常它告诉我,提供的参数无效,但我似乎无法理解它。我已经尝试添加空值来填充像groupBy这样的其他参数,但它一直告诉我参数是错误的。
继承我的代码
private String[] folderID = {MySQLiteHelper.COLUMN_FOLDERID};
private String[] folderTitle = {MySQLiteHelper.COLUMN_FOLDERNAME};
public Cursor findFolderId(String i){
String[] select = {i + "=" + folderTitle};
Cursor cursor = database.query(MySQLiteHelper.TABLE_FOLDERS, folderID, "WHERE", select);
return cursor;
编辑:
这是典型的错误
SQLiteDatabase类型中的方法查询(String,String [],String,String [],String,String,String)不适用于参数(String,String [],String,String [])
答案 0 :(得分:1)
您需要将您的更改为:
String[] columns = {"Column1", "Column2"}; // columns to select
String selection = "someCol = ?";
String[] args = {i}; // value added into where clause --> column = i
Cursor c = database.query(TABLE, columns, selection, args, null, null, null);
通常,列是您要获取的列,选择等同于where子句,args是将被替换的值,而不是 ?
(这称为占位符),顺序相同
答案 1 :(得分:0)
public Cursor findFolderId(String i){
String[] select = {i};
Cursor cursor = database.query(MySQLiteHelper.TABLE_FOLDERS, folderID, folderTitle + "=?", select);
return cursor;