游标在SQLite中返回Null

时间:2016-11-14 06:34:03

标签: android sqlite cursor

现在我想使用SQLite保存我的设置数据,但无论我做什么,游标总是返回null。 如果数据库为空,我已经输入了代码:

if (sqlHelper.getProfilesCount(MySQLHelper.TABLE_SETTING_NAME) == 0){
        sqlHelper.insertSettingNote(Constants.STR_LANG,Constants.STR_LOC,Constants.STR_SENS);
    }

但它没有帮助。 rawQuery和查询都不能帮我读取文件。 你能帮我吗? 这是MySQLHelper中的代码:

public SettingNote getSettingNote(String sql) {
    SettingNote stnote = null;
    Cursor cursor = getAll(sql);
    if (cursor != null) {
        stnote = cursorToSettingNote(cursor);
        cursor.close();
    }
    return stnote;
}

    public Cursor getAll(String sql) { // It always returning null
    Cursor cursor = null;
    try {
        //cursor = db.rawQuery("SELECT * FROM" + sql,null); // I try using both rawQuery and query
        String selectQuery = sql;
        String[] whereArgs = new String[] {"hn", "vi", "no"};
        cursor = db.query(selectQuery, null, "loc = ? lang = ? sensitive = ?", whereArgs , null, null, null);

        if (cursor != null && cursor.getCount() > 0) {
            if (cursor.moveToFirst()) {
                do {
                    //Looping cursor and fetching the value...
                } while (cursor.moveToNext());
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }
    return cursor;
}

这是我的设置注释:

public class SettingNote {
int id;
String lang, loc, sensitive;

public SettingNote(int id, String lang, String loc, String sensitive) {
    this.id = id;
    this.lang = lang;
    this.loc = loc;
    this.sensitive = sensitive;
}
public SettingNote(){};

public void setSensitive(String sensitive) {this.sensitive = sensitive;}

public void setLoc(String loc) {this.loc = loc;}

public void setLang(String lang) {this.lang = lang;}

public int getId() {return id;}

public String getLang() {return lang;}

public String getLoc() {return loc;}

public String getSensitive() {return sensitive;}

public void setId(int id) {this.id = id;}

}

0 个答案:

没有答案