我遇到了问题:
Caused by: android.database.sqlite.SQLiteException: near "SELECT": syntax error (code 1): , while compiling: SELECT tags FROM appDb_table_project WHERE SELECT DISTINCT tags
我有:
public static final String DB_NAME = "appDbProject";
public static final int DB_VERSION = 1;
public static final String DB_TABLE = "appDb_table_project";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_DESCRIPTION = "description";
public static final String COLUMN_TAGS = "tags";
public SQLiteDatabase mDB;
public Cursor getTags() {
String[] column = new String[] { COLUMN_TAGS };
//return mDB.query(DB_TABLE, column, "SELECT DISTINCT tags", null, null, null, null);
//return mDB.query(true, DB_TABLE, new String[] { COLUMN_TAGS }, null, null, COLUMN_TAGS, null, null, null);
//String query ="SELECT DISTINCT tags FROM appDb_table_staff";
//return mDB.rawQuery(query, null);
return mDB.query(true, DB_TABLE, new String[] { COLUMN_TAGS }, null, null, COLUMN_TAGS, null, null, null);
}
我正在尝试将SELECT DISTINCT语句用于字段“tags”中的数据并将其放入String []中,但我没有得到。
Cursor cursor = db.getTags();
String[] array = new String[cursor.getCount()];
int i = 0;
while (cursor.moveToNext()) {
String tag = cursor.getString(cursor.getColumnIndex("tags"));
array[i] = tag;
i++;
}
String[] from = array;
int[] to = new int[] { R.id.textViewTags };
我尝试了不同的选项,但永远我在这一行和我的方法“getTags”中得到了这个错误:
Cursor cursor = db.getTags();
我做错了什么?
UPD:
答案 0 :(得分:0)
只需更改以下行:
SELECT tags FROM appDb_table_project WHERE SELECT DISTINCT tags
到
SELECT tags FROM appDb_table_project
答案 1 :(得分:-1)
尝试添加"空间"
public Cursor getTags() {
String[] column = new String[] { COLUMN_TAGS };
//return mDB.query(DB_TABLE, column, " SELECT DISTINCT tags ", null, null, null, null);
//return mDB.query(true, DB_TABLE, new String[] { COLUMN_TAGS }, null, null, COLUMN_TAGS, null, null, null);
//String query =" SELECT DISTINCT tags FROM appDb_table_staff ";
//return mDB.rawQuery(query, null);
return mDB.query(true, DB_TABLE, new String[] { COLUMN_TAGS }, null, null, COLUMN_TAGS, null, null, null);
}