下载和提取图像集时出现以下错误,然后出现不幸的关闭弹出窗口。请帮帮我
05-26 13:01:54.637: E/SQLiteLog(15753): (5) database is locked
05-26 13:01:54.657: E/SQLiteDatabase(15753): Failed to open database '/data/data/org.com.clipToonz/databases/clipToonz.db'.
05-26 13:01:54.657: E/SQLiteDatabase(15753): android.database.sqlite.SQLiteDatabaseLockedException: database is locked (code 5): , while compiling: PRAGMA journal_mode
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:634)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:320)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:294)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:215)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at org.com.clipToonz.dbUtilities.ImageSetHandler.getImageSetIDByNameAndParentID(ImageSetHandler.java:187)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at org.apache.cordova.plugin.ExtractPlugin$unZipTask.doInBackground(ExtractPlugin.java:145)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at org.apache.cordova.plugin.ExtractPlugin$unZipTask.doInBackground(ExtractPlugin.java:1)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.os.AsyncTask$2.call(AsyncTask.java:288)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at java.util.concurrent.FutureTask.run(FutureTask.java:237)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
05-26 13:01:54.657: E/SQLiteDatabase(15753): at java.lang.Thread.run(Thread.java:841)
05-26 13:01:54.657: W/dalvikvm(15753): threadid=26: thread exiting with uncaught exception (group=0x41760ba8)
以下代码用于插入图片详细信息
DB_PATH=Constants.KEY_DBPATH;
String myPath = DB_PATH;
db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE);
ContentValues values = new ContentValues();
values.put(KEY_NAME,imageset.getName());
values.put(KEY_PARENTID,imageset.getParentID());
values.put(KEY_ISDIRECTORY ,imageset.getIsDirectory());
values.put(KEY_CATEGORYID, imageset.getCategoryID());
values.put(KEY_IMAGESETNAME, imageset.getImagesetName());
values.put(KEY_PRIMARYNAME, imageset.getPrimaryName());
// String query = "INSERT INTO " +imageset.getTableName()+ "("+KEY_IMAGESETNAME+","+KEY_NAME+","+KEY_PARENTID+","+KEY_ISDIRECTORY+","+KEY_CATEGORYID+","+KEY_PRIMARYNAME+") VALUES('"+imageset.getImagesetName()+"','"+imageset.getName()+"',"+imageset.getParentID()+","+imageset.getIsDirectory()+","+imageset.getCategoryID()+",'"+imageset.getPrimaryName()+"')";
//System.out.println(imageset.getTableName());
// Inserting Row
//db.execSQL(query);
db.insert(imageset.getTableName(), null, values);
db.close(); // Closing database connection
并检测现有图像细节
int returnValue=0;
//String num;
DB_PATH=Constants.KEY_DBPATH;
String name=imagesetp.getName();
int categoryid = imagesetp.getCategoryID();
String myPath = DB_PATH;
db = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS | SQLiteDatabase.OPEN_READWRITE);
String selectQuery="SELECT * FROM "+imagesetp.getTableName()+" WHERE "+KEY_NAME+"='"+String.valueOf(name)+"' AND parentid="+parentID+" AND categoryid ="+categoryid;
System.out.println("selectQuery " + selectQuery);
Cursor cursor = db.rawQuery(selectQuery,null);
// try{
if (cursor != null && cursor.getCount()!=0)
cursor.moveToFirst();
returnValue=Integer.parseInt(cursor.getString(0));
// }
// finally{
//cursor.close();
// db.close();
// }
cursor.close();
db.close();
return returnValue;
答案 0 :(得分:0)
由于我还不能写评论(需要50个声望),我写在这里 - 但不仅如此,这应该是你的答案:
您尝试在另一行代码中使用时打开数据库。为了避免不一致,数据库将自动锁定每个其他访问,但这一次。首先,您需要分配此资源(使用db.close() - 在您的代码中某处似乎丢失了),然后才能在其他地方使用它。
更多:
SQLiteDatabase db = new DataBaseHelper(context).getReadableDatabase();
和
SQLiteDatabase db = new DataBaseHelper(context).getWritableDatabase();
是获取数据库的更常用方法。
修改强>
我想我发现了你的错误。请在下次格式化您的代码 - 它会对您有所帮助!
if (cursor != null && cursor.getCount()!=0)
cursor.moveToFirst();
returnValue=Integer.parseInt(cursor.getString(0));
这是离开方法之前不会关闭数据库的地方!返回后,您的功能将被保留。在返回之前放置db.close()
。
祝你好运 文斯