开发者

Select statement problem in Sqlite android

hello expert,

i cant able to execute select statement can you help me here is code i am attach

try
    {
    Insall_app_db i1 = new Insall_app_db();
    int s = i1.GetUserData(this, tableName);
    System.out.println("i1.app_id:::: "+s);
    Toast.makeText(getBaseContext(),"app_id"+s, Toast.LENGTH_LONG).show();
    }catch (Exception e) {
        e.printStackTrace();
    }


public int GetUserDa开发者_C百科ta(Context context,String tablename)
{
            c = sampleDB.rawQuery("SELECT * FROM " +
                tablename +
                "", null);

            if(c!=null)
            {
                if(c.moveToFirst())
                {
                    do
                    {
                        app_id=c.getInt(c.getColumnIndex("app_id"));
                        /*app_name=c.getString(c.getColumnIndex("app_name"));
                        pname=c.getString(c.getColumnIndex("pname"));
                        version_name=c.getString(c.getColumnIndex("version_name"));
                        versionCode=c.getString(c.getColumnIndex("versionCode"));
                        icon=c.getString(c.getColumnIndex("icon"));
                        app_name=c.getString(c.getColumnIndex("date"));*/




                    }while(c.moveToNext());



                    }   

                }       

            return app_id;
}


Hi Please try below code.


public int GetUserData(Context context,String tablename)
{
    int app_id=0;
    try {
        sampleDB = myDbHelper.openDataBase();
    } catch (SQLException sqle) {
        throw sqle;
    }
    sampleDB = myDbHelper.getWritableDatabase();
        c = sampleDB.rawQuery("SELECT * FROM " +
            tablename, null);

        if(c!=null)
        {
            if(c.moveToFirst())
            {
                do
                {
                    app_id=c.getInt(c.getColumnIndex("app_id"));
                }while(c.moveToNext());



                }   

            }       

        return app_id;
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜