2015-12-16 42 views
-1

我正在关注本教程http://mobisys.in/blog/2012/01/tutorial-using-database-in-android-applications/以使用我的android应用程序创建外部数据库。从android应用程序附带的数据库提取日期

从数据库中获取数据时,我无法应用where子句。 这就是我迄今为止所做的。

c=myDbHelper.query("level1", null, "_id=2", null, null,null, null); 
    if(c.moveToFirst()) 
    { 
     do { 

     Toast.makeText(Level1.this, 
        "_id: " + c.getString(0) + "\n" + 
        "name: " + c.getString(1) + "\n" 
        , 
        Toast.LENGTH_LONG).show(); 

     } while (c.moveToNext()); 
    } 

的databaseHelper类

public Cursor query(String table,String[] columns, String selection,String[] selectionArgs,String groupBy,String having,String orderBy){ 
    return myDataBase.query("level1", null, "_id", null, null, null, null); 


} 

谁能帮助我?

回答

1

当您拨打myDbHelper.query时,您通过"_id=2"作为selection。但在你的DB助手query方法中,selection从不使用(其他参数也一样)。

你可能想改变query喜欢的东西:

public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy){ 
    // double check parameters I did type that here (no IDE) 
    return myDataBase.query(table, columns, selection, selectionArgs, groupBy, having, orderBy); 
} 

参见,the documentation of SQLiteDatabase

+0

谢谢你,它的工作。我应该检查一下它刚刚掉下来的文档。反正谢谢你。 –

相关问题