你好专家,
我无法执行select语句你可以帮助我这里是我附加的代码
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 GetUserData(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;
}
答案 0 :(得分:3)
您好请尝试以下代码。
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;
}