我在數據庫中執行一個簡單的插入查詢。
但我得到的例外如標題所示。
請幫幫我。java.lang.illegalstateexception試圖重新打開一個已經關閉的對象sqlitequery prblem
代碼如下。
公共無效insertAutoAlbumDetails(字符串SETID,字符串ALBUMID, 字符串類型,字符串ALBUMNAME){
String query = "INSERT INTO "
+ ALBUM_DETAILS
+ "("
+ ALBUM_ID
+ ","
+ ALBUM_NAME
+ ","
+ ALBUM_TYPE
+ ","
+ USER_ID
+ ","
+ ALBUM_SETID
+ ") SELECT \""
+ albumid
+ "\",\""
+ albumName
+ "\",\""
+ Type
+ "\",\""
+ AppPreferences.getAppPreferences(context).getString(
AppConstants.USER_ID, "")
+ "\",\""
+ setId
+ "\" WHERE NOT EXISTS "
+ "("
+ "SELECT 1 FROM "
+ ALBUM_DETAILS
+ " WHERE "
+ ALBUM_ID
+ "=\""
+ albumid
+ "\" AND "
+ USER_ID
+ "=\""
+ AppPreferences.getAppPreferences(context).getString(
AppConstants.USER_ID, "") + "\")";
this.Query(query);//// i get exception on this line.
}
收到以下異常...
02-11 18:11:35.370: W/System.err(26820): java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.app.quirl/databases/canvera.sqlite
02-11 18:11:35.370: W/System.err(26820): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:55)
02-11 18:11:35.370: W/System.err(26820): at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1648)
02-11 18:11:35.370: W/System.err(26820): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
02-11 18:11:35.370: W/System.err(26820): at com.app.quirl.db.GetDB.Query(GetDB.java:50)
02-11 18:11:35.370: W/System.err(26820): at com.app.quirl.db.AlbumDetailsDao.insertAutoAlbumDetails(AlbumDetailsDao.java:119)
02-11 18:11:35.370: W/System.err(26820): at com.app.quirl.GetAutoCountService.uploadImages(GetAutoCountService.java:108)
02-11 18:11:35.370: W/System.err(26820): at com.app.quirl.GetAutoCountService.access$0(GetAutoCountService.java:62)
02-11 18:11:35.370: W/System.err(26820): at com.app.quirl.GetAutoCountService$startUploadImage.doInBackground(GetAutoCountService.java:56)
02-11 18:11:35.370: W/System.err(26820): at com.app.quirl.GetAutoCountService$startUploadImage.doInBackground(GetAutoCountService.java:1)
02-11 18:11:35.370: W/System.err(26820): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-11 18:11:35.370: W/System.err(26820): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-11 18:11:35.370: W/System.err(26820): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-11 18:11:35.370: W/System.err(26820): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-11 18:11:35.370: W/System.err(26820): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-11 18:11:35.370: W/System.err(26820): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-11 18:11:35.370: W/System.err(26820): at java.lang.Thread.run(Thread.java:856)
您的數據庫已經關閉,那麼即使您嘗試將數據插入數據庫表中,您必須重新打開並插入數據。 –