Android SQLite,尝试从数据库中获取数据时出现语法错误

时间:2014-11-19 18:19:52

标签: android sqlite select

我是这个

  

11-19 19:16:38.920:E / SQLiteLog(5568):( 1)靠近“SELECT”:语法   错误

错误的Android选择查询,然后我的应用程序崩溃,我无法理解为什么会发生。

String selectQuery = "SELECT  * FROM " + MySQLiteHelper.TABLE_CATEGORIA;
            Log.e("DB", "select query "+selectQuery);
            SQLiteDatabase db = dbHelper.getReadableDatabase();
            Log.e("DB", "db "+db);
            Cursor c = db.rawQuery(selectQuery, null);
            if (c.moveToFirst()) {
                do {
                    if(c.getString(c.getColumnIndex(MySQLiteHelper.COLUMN_NOMECATEGORIA)).equalsIgnoreCase(name)){
                        id=c.getInt(c.getColumnIndex(MySQLiteHelper.COLUMN_ID));
                        color=c.getFloat(c.getColumnIndex(MySQLiteHelper.COLUMN_COLORE));
                        return color;
                    }
                    coloriusati.add(c.getFloat(c.getColumnIndex(MySQLiteHelper.COLUMN_COLORE)));
                } while (c.moveToNext());
            }

1 个答案:

答案 0 :(得分:0)

SELECT命令后有两倍的空格。

String selectQuery = "SELECT  * FROM " + MySQLiteHelper.TABLE_CATEGORIA;

删除'SELECT'后的额外空格,它应该可以工作。

String selectQuery = "SELECT * FROM " + MySQLiteHelper.TABLE_CATEGORIA;