从数据库中读取Android,查询

时间:2015-05-29 16:07:42

标签: android database cursor

我正在尝试读取我创建的数据库,并在LogCat中显示:“样式包含错误条目的键:0x01010479”和“(1)没有这样的表:FeedReader”。我已经测试了很多时间而且我不知道问题

Context contexto = this;
        DataBase dbHelper=new DataBase(contexto);
        SQLiteDatabase db=dbHelper.getWritableDatabase();
        String[] columns={"COLUMNname","COLUMNimage","COLUMNsound"};
        Cursor c=db.query("FeedReader", null, null, null, null, null, null);
        if (c.moveToFirst()) {
            //Recorremos el cursor hasta que no haya más registros
            for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
                nameC[c.getCount()]= c.getString(1);
                //imageC[c.getCount()]= c.getString(2);
                //soundC[c.getCount()]= c.getString(3);
            }
        }
        c.close();
        db.close();
    }catch(SQLiteException e)
    { System.out.println(e.getMessage());}

以下是我创建数据库的方法

public class DataBase extends SQLiteOpenHelper{

public static final int DATABASE_VERSION = 1;
public static final String nameDataBase = "FeedReader";

public String createEntires="CREATE TABLE dBsound(" +
    "id INTEGER PRIMARY KEY AUTOINCREMENT," +
    "COLUMNname TEXT,COLUMNimage TEXT,COLUMNsound TEXT)";
public String deleteEntires =
        "DROP TABLE IF EXISTS dBsound";

public DataBase(Context context) {
    super(context, nameDataBase, null, DATABASE_VERSION);
    // TODO Auto-generated constructor stub
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(createEntires);

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL(deleteEntires);
    onCreate(db);
}


public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    onUpgrade(db, oldVersion, newVersion);
}

1 个答案:

答案 0 :(得分:4)

实际上您的表名称dBsound

 Cursor c=db.query("dBsound", null, null, null, null, null, null);

FeedReader是您的数据库名称。