加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

SQLite查找表是否有时有记录

发布时间:2020-12-12 20:37:20 所属栏目:百科 来源:网络整理
导读:SQLiteDatabase db= SQLiteDatabase.openOrCreateDatabase(this.getFilesDir()+"/Diary_aks.db3",null);//在Oncreate中打开数据库Diary_aks.db3 if(tabIsExist("User")){//查找表USer是不为空 则跳转到LoginActivity intent=new Intent(IndexActivity.this,L


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

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

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

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; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读