以下是我的表格:
db.execSQL("CREATE TABLE "+ callTable+" ("+ colID + " INTEGER PRIMARY KEY AUTOINCREMENT, "+ colPhNum + " TEXT, " + colDur + " INTEGER, "
+ colDate + " INTEGER, " + colDay + " TEXT, " + colYear + " INTEGER, " + colType + " TEXT, " + colStTime + " TEXT, " + colHour + " INTEGER, " + colMonth + " INTEGER)");
我试图执行此查询:
SQLiteDatabase db=this.getWritableDatabase();
String j = "SELECT " + colPhNum + "," + "SUM(" +colDur +") FROM " + callTable +" WHERE " + colYear + "=" + y+ " AND " +colMonth +"=" + m + " AND " +colDate + "=" + d + " AND " + colHour + ">" + h
+ " GROUP BY " + colPhNum;
Cursor c = db.rawQuery(j,null);
c.close();
return c;
但这不起作用。这是错误日志:
D/AndroidRuntime( 209): Shutting down VM
W/dalvikvm( 209): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 209): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 209): java.lang.IllegalStateException: attempt to acquire a reference on a close SQLiteClosable
E/AndroidRuntime( 209): at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:31)
E/AndroidRuntime( 209): at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:69)
E/AndroidRuntime( 209): at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:288)
E/AndroidRuntime( 209): at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:269)
请帮忙。
答案 0 :(得分:0)
在查询之前添加以下代码并尝试
db = openOrCreateDatabase( “databasename.db” ,SQLiteDatabase.CREATE_IF_NECESSARY , 空值 );