1.是获取数据库
2.根据数据可查判断是否存在某表名
3.存在就对该表进行增删改查
注:注意权限
/**
* 获取数据库然后
* @param
* @return
*/
public static SQLiteDatabase openDB(String dbPath){
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(
dbPath(数据库地址), null);
}
/**
* 判断某张表是否存在
* @param tabName 表名
* @return
*/
public static boolean tabIsExist(SQLiteDatabase db,String tabName){
boolean result = false;
if(tabName == null){
return false;
}
Cursor cursor = null;
try {
String sql = "select count(*) as c from sqlite_master where type ='table' and name ='" + tabName.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;
}