微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SQLite查找表是否有时有记录


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

原文地址:https://www.jb51.cc/sqlite/202296.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐