我无法打开数据库异常。只有在我触摸我的应用程序后,我才能获得此异常。
所以我的问题是:版本差异是否会导致此次崩溃? 如何将adb shell sqlite3 --version升级到sqlite3版本3.7.17
我正在使用ICS Os。
我的问题的任何其他解决方案都会有所帮助
这是我在java图层上的代码
public static DatabaseHandler getInstance(Context context) {
if (oDatabaseHandler == null)
{
oDatabaseHandler = new DatabaseHandler(context.getApplicationContext());
}
return oDatabaseHandler;
}
public DatabaseHandler(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
String path = context.getDatabasePath(DatabaseHandler.DATABASE_NAME).toString();
}
//创建表
@Override
public void onCreate(SQLiteDatabase db)
{
String CREATE_TABLE_DIAGNOSIS = "CREATE TABLE IF NOT EXISTS " + TABLE_Diagnosistble + "("+KEY_DiagID+ " TEXT PRIMARY KEY ," +KEY_PName+ " TEXT ," +KEY_HospitalNumber+ " TEXT ," +KEY_Gender+ " TEXT ," + KEY_Pacemaker+ " TEXT ," +KEY_DiagType+ " TEXT , " +KEY_Age+ " TEXT ," + KEY_D_DeviceID+ " TEXT ," +KEY_D_DiagStrtTime+ " TEXT ," +KEY_D_DiagEndTime+ " TEXT ," +KEY_D_DiagStatus+ " TEXT ," +KEY_D_ReportStatus+ " TEXT , " +KEY_D_UploadStatus+ " TEXT , " +KEY_D_ChestLead1+ " TEXT ," +KEY_D_ChestLead2+ " TEXT " + ");";
db.execSQL(CREATE_TABLE_DIAGNOSIS);
String CREATE_TABLE_PASTEVENTS = "CREATE TABLE IF NOT EXISTS " + TABLE_Pasteventstble + "("+KEY_SerNo+ " INTEGER ," +KEY_Trans_ID+ " TEXT ," +KEY_PEDiagID+ " TEXT ," +KEY_AlarmID+ " INTEGER ," +KEY_PktCounter+ " INTEGER , "+KEY_EventNo+" INTEGER ," +KEY_StartTime+ " TEXT ," +KEY_EndTime+ " TEXT , " + KEY_ECG_UploadStatus+ " TEXT , " + KEY_ECGMode+ " INTEGER " + ");";
db.execSQL(CREATE_TABLE_PASTEVENTS);
}
这是FetchLastDiagID //获取上次诊断ID已创建
public HistoryTble FetchLastDiagnosisID()
{
String selectQuery = "SELECT * FROM " + TABLE_Historytble + "";
SQLiteDatabase db = this.getWritableDatabase();
if(db == null)
return null;
Cursor cursor = db.rawQuery(selectQuery, null);
HistoryTble oHistryTble = new HistoryTble();
try
{
if(cursor.getCount() > 0)
{
if (cursor.moveToFirst())
do
{
oHistryTble.SetDiagnosisID(cursor.getString(1));
} while(cursor.moveToNext());
}
else
{
oHistryTble = null;
}
}
finally
{
if(db != null)
{
cursor.close();
db.close();
}
}
return oHistryTble;
}
这是我的崩溃日志
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:1013)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:986)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1051)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:779)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:157)
at com.cdl.Database.DatabaseHandler.FetchLastDiagnosisID(DatabaseHandler.java:845)
at com.cdl.mircam.DiagCreation.GenerateDiagID(DiagCreation.java:1141)
at com.cdl.mircam.DiagCreation.onCreate(DiagCreation.java:249)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
... 11 more
答案 0 :(得分:0)
我在NDK层使用Sqlite函数调用。
对于我正在使用的每个sqlite函数调用
sqlite3_finalize(HRLY_stmt);
HRLY_Result = sqlite3_close_v2(HRLY_db);
但在一个函数中我关闭了数据库而没有完成。经过长时间的运行,这对我来说是个问题。我在App层上得到了这个例外(说无法打开数据库异常)
注意:确保任何条件下的任何数据库仅在完成后才关闭数据库。
同样的问题在UI点击中长期导致 TransactionTooLarge例外
结论它解决了我的两个问题
Sqlite无法打开长期看到的数据库异常
长期看到的TransactionToolarge异常