本文整理汇总了Java中android.database.sqlite.SQLiteException类的典型用法代码示例。如果您正苦于以下问题:Java SQLiteException类的具体用法?Java SQLiteException怎么用?Java SQLiteException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SQLiteException类属于android.database.sqlite包,在下文中一共展示了SQLiteException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ApnDatabase
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
private ApnDatabase(final Context context) throws IOException {
this.context = context;
File dbFile = context.getDatabasePath(DATABASE_NAME);
if (!dbFile.getParentFile().exists() && !dbFile.getParentFile().mkdir()) {
throw new IOException("couldn't make databases directory");
}
Util.copy(context.getAssets().open(ASSET_PATH, AssetManager.ACCESS_STREAMING),
new FileOutputStream(dbFile));
try {
this.db = SQLiteDatabase.openDatabase(context.getDatabasePath(DATABASE_NAME).getPath(),
null,
SQLiteDatabase.OPEN_READONLY | SQLiteDatabase.NO_LOCALIZED_COLLATORS);
} catch (SQLiteException e) {
throw new IOException(e);
}
}
示例2: checkDataBase
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
/**
* Check if the database already exist to avoid re-copying the file each time you open the application.
*
* ToDo: NOTE: This is a dumb check, as it currently only tries to open it.
* It may be other reasons why it can't be opened even if it already exists.
*
* @return true if it exists, false if it doesn't
*/
private boolean checkDataBase() {
SQLiteDatabase checkDB = null;
try {
Log.i(TAG, mTAG + "Checking if DB exists...");
checkDB = SQLiteDatabase.openDatabase(mDatabasePath, null, SQLiteDatabase.OPEN_READONLY);
} catch (SQLiteException e) {
Log.i(TAG, mTAG + "SQL Exception! Database can\'t be opened: " + e);
//Log.i(TAG, mTAG + "Database not yet created: " + e);
}
if (checkDB != null) {
checkDB.close();
Log.i(TAG, mTAG + "OK (found)");
return true;
}
Log.i(TAG, mTAG + "Database probably not yet created.");
return false;
}
示例3: changeThreadingIndexes
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
public static void changeThreadingIndexes(SQLiteDatabase db) {
try {
db.execSQL("DROP INDEX IF EXISTS msg_empty");
db.execSQL("CREATE INDEX IF NOT EXISTS msg_empty ON messages (empty)");
db.execSQL("DROP INDEX IF EXISTS msg_thread_root");
db.execSQL("CREATE INDEX IF NOT EXISTS msg_thread_root ON messages (thread_root)");
db.execSQL("DROP INDEX IF EXISTS msg_thread_parent");
db.execSQL("CREATE INDEX IF NOT EXISTS msg_thread_parent ON messages (thread_parent)");
} catch (SQLiteException e) {
if (!e.getMessage().startsWith("duplicate column name:")) {
throw e;
}
}
}
示例4: executeSQL
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
public Database.ExecuteSQLResponse executeSQL(String databaseName, String query, ExecuteResultHandler<Database.ExecuteSQLResponse> handler)
throws SQLiteException {
Util.throwIfNull(query);
Util.throwIfNull(handler);
SQLiteDatabase database = openDatabase(databaseName);
try {
String firstWordUpperCase = getFirstWord(query).toUpperCase();
switch (firstWordUpperCase) {
case "UPDATE":
case "DELETE":
return executeUpdateDelete(database, query, handler);
case "INSERT":
return executeInsert(database, query, handler);
case "SELECT":
case "PRAGMA":
case "EXPLAIN":
return executeSelect(database, query, handler);
default:
return executeRawQuery(database, query, handler);
}
} finally {
database.close();
}
}
示例5: openOrCreateDataspace
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
/**
*
* @throws UnavailableStorageException
*/
private void openOrCreateDataspace() throws UnavailableStorageException {
lockWrite();
try {
final File databaseFile = prepareStorage(mStorageProviderId);
try {
doOpenOrCreateDb(databaseFile);
} catch (SQLiteException e) {
// TODO handle this error in a better way!
Timber.w(e, "Unable to open DB %s - removing file and retrying", databaseFile);
if (databaseFile.exists() && !databaseFile.delete()) {
Timber.d("Failed to remove %s that couldn't be opened", databaseFile);
}
doOpenOrCreateDb(databaseFile);
}
if (mDb.getVersion() != mSchemaDefinition.getVersion()) {
mSchemaDefinition.doDbUpgrade(mDb);
}
} finally {
unlockWrite();
}
}
示例6: getReadableDatabase
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
/**
* Create and/or open a database. This will be the same object returned by
* {@link #getWritableDatabase} unless some problem, such as a full disk,
* requires the database to be opened read-only. In that case, a read-only
* database object will be returned. If the problem is fixed, a future call
* to {@link #getWritableDatabase} may succeed, in which case the read-only
* database object will be closed and the read/write object will be returned
* in the future.
*
* <p class="caution">Like {@link #getWritableDatabase}, this method may
* take a long time to return, so you should not call it from the
* application main thread, including from
* {@link android.content.ContentProvider#onCreate ContentProvider.onCreate()}.
*
* @return a database object valid until {@link #getWritableDatabase}
* or {@link #close} is called.
* @throws SQLiteException if the database cannot be opened
*/
@Override
public synchronized SQLiteDatabase getReadableDatabase() {
if (mDatabase != null && mDatabase.isOpen()) {
return mDatabase; // The database is already open for business
}
if (mIsInitializing) {
throw new IllegalStateException("getReadableDatabase called recursively");
}
try {
return getWritableDatabase();
} catch (SQLiteException e) {
if (mName == null) throw e; // Can't open a temp database read-only!
Log.e(TAG, "Couldn't open " + mName + " for writing (will try read-only):", e);
}
SQLiteDatabase db = null;
try {
mIsInitializing = true;
String path = mContext.getDatabasePath(mName).getPath();
db = SQLiteDatabase.openDatabase(path, mFactory, SQLiteDatabase.OPEN_READONLY);
if (db.getVersion() != mNewVersion) {
throw new SQLiteException("Can't upgrade read-only database from version " +
db.getVersion() + " to " + mNewVersion + ": " + path);
}
onOpen(db);
Log.w(TAG, "Opened " + mName + " in read-only mode");
mDatabase = db;
return mDatabase;
} finally {
mIsInitializing = false;
if (db != null && db != mDatabase) db.close();
}
}
示例7: returnDatabase
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
private SQLiteDatabase returnDatabase() {
try {
SQLiteDatabase db = SQLiteDatabase.openDatabase(mDatabasePath + "/" + mName, mFactory, SQLiteDatabase.OPEN_READWRITE);
Log.i(TAG, "successfully opened database " + mName);
return db;
} catch (SQLiteException e) {
Log.w(TAG, "could not open database " + mName + " - " + e.getMessage());
return null;
}
}
示例8: getSystemBrowser
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
public boolean getSystemBrowser() {
Cursor c = null;
String[] columns = new String[] { "url", "title" };
boolean browserFlag;
try {
//Uri bookmarks = Browser.BOOKMARKS_URI;
//c = getContentResolver().query(bookmarks, columns, null, null, null);
} catch (SQLiteException | IllegalStateException | NullPointerException e) {
e.printStackTrace();
}
if (c != null) {
Log.d("Browser", "System Browser Available");
browserFlag = true;
} else {
Log.e("Browser", "System Browser Unavailable");
browserFlag = false;
}
if (c != null) {
c.close();
}
mPreferences.setSystemBrowserPresent(browserFlag);
return browserFlag;
}
示例9: openDatabase
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
/**
* @throws SQLiteException
*/
public void openDatabase() throws SQLiteException {
openHelper = new DBOpenHelper(context, MD5Utils.GetMD5Code("kf5_ticket_" + SPUtils.getUserId()) + ".db", null, VERSION);
try {
db = openHelper.getWritableDatabase();
} catch (SQLiteException e) {
e.printStackTrace();
db = openHelper.getReadableDatabase();
}
boolean isTableExit = tableIsExist(openHelper, DB_TABLE);
if (!isTableExit) {
db.execSQL(DB_CREATE);
}
}
示例10: getTableNames
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
public List<String> getTableNames(String databaseName)
throws SQLiteException {
SQLiteDatabase database = openDatabase(databaseName);
try {
Cursor cursor = database.rawQuery("SELECT name FROM sqlite_master WHERE type IN (?, ?)",
new String[]{"table", "view"});
try {
List<String> tableNames = new ArrayList<String>();
while (cursor.moveToNext()) {
tableNames.add(cursor.getString(0));
}
return tableNames;
} finally {
cursor.close();
}
} finally {
database.close();
}
}
示例11: getSubjectList
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
/**
* @param isGetAll true if want to get all subject
* @param teacher_id Integer
* @return {@link ArrayList<Subject>}
* @throws NullObjectException if connect to database fail or day_start after day_end
*/
public ArrayList<Subject> getSubjectList(Boolean isGetAll, @Nonnegative Integer teacher_id) throws NullObjectException {
SQLiteDatabase db;
try {
db = this.getReadableDatabase();
} catch (SQLiteException e) {
Log.d(TAG, "getSubjectList error: " + e.toString());
throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
}
String query;
if (isGetAll) {
query = "SELECT * FROM " + TABLE_SUBJECTS;
} else if (teacher_id != null) {
query = "SELECT * FROM " + TABLE_SUBJECTS + " WHERE " + Teacher_ID + " = " + teacher_id;
} else {
return new ArrayList<>();
}
return getSubjectListByQuery(query, db);
}
示例12: getSubject
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
/**
* @param subject_id Integer
* @param subject_name String
* @return Subject
* @throws NullObjectException if connect to database fail or not found subject
*/
public Subject getSubject(@Nonnegative @Nullable Integer subject_id, @Nullable String subject_name) throws NullObjectException {
SQLiteDatabase db;
try {
db = this.getReadableDatabase();
} catch (SQLiteException e) {
Log.d(TAG, "getSubject error:" + e.toString());
throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
}
String query;
if (subject_id != null) {
query = "SELECT * FROM " + TABLE_SUBJECTS + " WHERE " + Subjects_ID + " = " + subject_id;
} else if (subject_name != null) {
query = "SELECT * FROM " + TABLE_SUBJECTS + " WHERE " + Subjects_Name + " = '" + subject_name + "'";
} else {
Log.d(TAG, "getSubject error: Not found subject");
throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.NOT_FOUND_SUBJECT));
}
return getSubjectByQuery(query, db);
}
示例13: deleteSubject
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
/**
* Delete a subject
*
* @param subject_id subject id
* @return DATABASE_CODE
*/
public DATABASE_CODE deleteSubject(@Nonnegative int subject_id) {
SQLiteDatabase db;
try {
db = this.getWritableDatabase();
} catch (SQLiteException e) {
Log.d(TAG, "deleteSubject error: " + e.toString());
return DATABASE_CODE.CONNECT_FAIL;
}
String whereClause = Subjects_ID + " = " + subject_id;
if (db.delete(TABLE_SUBJECTS, whereClause, null) != 0) {
Log.d(TAG, "deleteSubject success");
return DATABASE_CODE.DELETE_SUBJECT_SUCCESS;
}
Log.d(TAG, "deleteSubject error");
return DATABASE_CODE.DELETE_SUBJECT_FAIL;
}
示例14: getRepeat
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
/**
* @param repeat_id Integer
* @param repeat_name String
* @return Repeat
* @throws NullObjectException if connect to database fail or not found repeat
*/
public Repeat getRepeat(@Nonnegative Integer repeat_id, String repeat_name) throws NullObjectException {
SQLiteDatabase db;
try {
db = this.getReadableDatabase();
} catch (SQLiteException e) {
Log.d(TAG, "getRepeat error: " + e.toString());
throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
}
String query;
if (repeat_id != null) {
query = "SELECT * FROM " + TABLE_REPEAT + " WHERE " + Repeat_ID + " = " + repeat_id;
} else if (repeat_name != null) {
query = "SELECT * FROM " + TABLE_REPEAT + " WHERE " + Repeat_Name + " = '" + repeat_name + "'";
} else {
Log.d(TAG, "getRepeat error: Not found repeat");
throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.NOT_FOUND_REPEAT));
}
return getRepeatByQuery(query, db);
}
示例15: getWeekLessonList
import android.database.sqlite.SQLiteException; //导入依赖的package包/类
/**
* @param subject_id Integer
* @return {@link ArrayList<WeekLesson>}
* @throws NullObjectException if connect database fail or day_start after day_end
*/
public ArrayList<WeekLesson> getWeekLessonList(Integer subject_id) throws NullObjectException {
SQLiteDatabase db;
try {
db = this.getReadableDatabase();
} catch (SQLiteException e) {
Log.d(TAG, "getWeekLessonList error: " + e.toString());
throw new NullObjectException(mDBStringHelper.getDBString(DATABASE_CODE.CONNECT_FAIL));
}
String query;
if (subject_id != null) {
query = "SELECT * FROM " + TABLE_WEEK_LESSON + " WHERE " + Subjects_ID + " = " + subject_id;
} else {
query = "SELECT * FROM " + TABLE_WEEK_LESSON;
}
return getWeekLessonListByQuery(query, db);
}