sqlite中判断某个表是否存在的方法,贴出来供大家参考

Java代码

/**

*判断某张表是否存在

*@paramtabName表名

*@return

*/

publicbooleantabbleIsExist(StringtableName){

booleanresult=false;

if(tableName==null){

returnfalse;

}

SQLiteDatabasedb=null;

Cursorcursor=null;

try{

db=this.getReadableDatabase();

Stringsql="selectcount(*)ascfromSqlite_masterwheretype='table'andname='"+tableName.trim()+"'";

cursor=db.rawQuery(sql,null);

if(cursor.moveToNext()){

intcount=cursor.getInt(0);

if(count>0){

result=true;

}

}

}catch(Exceptione){

//TODO:handleexception

}

returnresult;

}