我使用如下代码完成
public boolean tabbleIsExist(SQLiteDatabase db, String tableName){
boolean result = false;
if(tableName == null){
return false;
}
Cursor cursor = null;
try {
String sql = "select count(*) as c from Sqlite_master 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;
}
之前我采用“select * from table”的方法,然后表不存会直接报错,因此不可以。上面的方法是最好的