The following is my table :
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)");开发者_如何学运维
and I am trying to get execute this query :
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;
But this is not working. This is the error log:
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)
Please help.
Before the query add below code and try
db = openOrCreateDatabase( "databasename.db" , SQLiteDatabase.CREATE_IF_NECESSARY , null );
精彩评论