SQLiteException:near" FROM":语法错误

时间:2016-05-27 11:00:30

标签: android sqlite

我编译请求时遇到错误。

这是我的日志:android.database.sqlite.SQLiteException:near" FROM&#34 ;:语法错误(代码1):,同时编译:SELECT nom,prenom,numero,FROM Ichar WHERE id =?

这是我的MySQLite类的一部分似乎关注错误:

public Character getCharacterById(int Id) {

    SQLiteDatabase db = getWritableDatabase();
    String query = "SELECT  " +
            "nom" + "," +
            "prenom" + "," +
            "numero" + "," +
            " FROM  " + CHARACTER_TABLE
            + " WHERE  " +
            "id" + "=?";

    Character character = new Character();


    Cursor cursor = db.rawQuery(query, new String[]{String.valueOf(Id)});

    if (cursor.moveToFirst()) {
        do {
            character.character_Id = cursor.getInt(cursor.getColumnIndex("id"));
            character.nom = cursor.getString(cursor.getColumnIndex("nom"));
            character.prenom = cursor.getString(cursor.getColumnIndex("prenom"));
            character.numero = cursor.getString(cursor.getColumnIndex("numero"));

        } while (cursor.moveToNext());



    }
    cursor.close();
    db.close();
    return character;

你能帮助我吗?

谢谢。

3 个答案:

答案 0 :(得分:1)

"numero" + "," +

- >

"numero" + 

答案 1 :(得分:0)

尝试像这样进行查询

 String query = "SELECT  " +
        "nom" + "," +
        "prenom" + "," +
        "numero" + 
        " FROM  " + CHARACTER_TABLE
        + " WHERE  " +
        "id" + "=?";

答案 2 :(得分:-2)

我认为问题在于,你有2个空格。

 SQLiteDatabase db = getWritableDatabase();
String query = "SELECT  " +
        "nom" + "," +
        "prenom" + "," +
        "numero" + "," +
        " FROM  " + CHARACTER_TABLE
        + " WHERE  " +
        "id" + "=?";

当你把"来自" + CHARACTER_TABLE白色空格使查询出错。