黑马程序员技术交流社区
标题:
sqlitedatabase问题
[打印本页]
作者:
诺忔。初禾、
时间:
2014-5-10 23:18
标题:
sqlitedatabase问题
sqlitedatabase怎么判断存不存在数据库表。新手求教
作者:
诺忔。初禾、
时间:
2014-5-11 22:53
没人知道么
作者:
诺忔。初禾、
时间:
2014-5-11 22:58
?????????
作者:
Jero
时间:
2014-5-13 01:28
/**
* 判断某张表是否存在
* @param tabName 表名
* @return
*/
public boolean tabIsExist(String tabName){
boolean result = false;
if(tabName == null){
return false;
}
SQLiteDatabase db = null;
Cursor cursor = null;
try {
db = this.getReadableDatabase();
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;
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2