SQLite查找表是否有时有记录

前端之家收集整理的这篇文章主要介绍了SQLite查找表是否有时有记录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


sqliteDatabase db= sqliteDatabase.openOrCreateDatabase(this.getFilesDir()+"/Diary_aks.db3",null);//在Oncreate中打开数据库Diary_aks.db3

if(tabIsExist("User")){//查找表USer是不为空@H_404_7@ 则跳转到LoginActivity
@H_404_7@intent=new Intent(IndexActivity.this,LoginActivity.class);@H_404_7@
@H_404_7@}
@H_404_7@else{//查找表USer为空@H_404_7@ 则跳转到RegistActivity
@H_404_7@intent=new Intent(IndexActivity.this,RegistActivity.class);
@H_404_7@}
@H_404_7@startActivity(intent);
@H_404_7@}

@H_404_7@/**
@H_404_7@* 判断表tabName是否为空
@H_404_7@* @param tabName 表名
@H_404_7@* @return boolean
@H_404_7@*/

public boolean tabIsExist(String tabName){

boolean result = false; if(tabName == null){ return false; } Cursor cursor = null; try { DataBaSEOpenHelper dbh=new DataBaSEOpenHelper(IndexActivity.this);// String sql = "select count(*) from User ";//USer表名 cursor = dbh.getReadableDatabase().rawQuery(sql,null); if(cursor.moveToNext()){ int count = cursor.getInt(0); if(count>0){ result = true; } } } catch (Exception e) { // TODO: handle exception } return result; }

猜你在找的Sqlite相关文章