//判断数据库中的表是否存在
原文链接:https://www.f2er.com/sqlite/201934.html注意:DBInfo是表名 |
cmd.CommandText = "SELECT COUNT(*) FROM sqlite_master where type='table' and name='DBInfo'" ; |
sqlite 中判断某个表是否存在的方法,贴出来供大家参考(java 、android) public boolean tabbleIsExist(String tableName){ boolean result = false; if(tableName == null){ return false; } sqliteDatabase db = null; Cursor cursor = null; try { db = this.getReadableDatabase(); String sql = "select count(*) as c from "+AppConstant.DataBaseName+" where type ='table' and name ='"+tableName.trim()+"' "; cursor = db.rawQuery(sql,null); if(cursor.moveToNext()){ int count = cursor.getInt(0); if(count>0){ result = true; } } } catch (Exception e) { // TODO: handle exception } return result; }