启动我的应用程序时,它应该只创建一个SQLite数据库。但是,根据logcat,会创建一个数据库,插入一行,然后再次创建数据库。 然后它说;
A SQLiteConnection object for database '/data/data/com.example.wolfe_000.final_final_zeno/databases/User_Info' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed.
我以前尝试在与数据库进行交互后关闭数据库,它似乎对我没用。我真的很感激一些建议,我是SQLite的新手,我完全迷失了。这是代码;
package com.example.wolfe_000.final_final_zeno;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
/**
* Created by wolfe_000 on 19/04/2015.
*/
public class DatabaseOperations extends SQLiteOpenHelper {
public static int database_version = 1;
public String CREATE_QUERY = "CREATE TABLE " + TableData.TableInfo.TABLE_NAME + "(" + TableData.TableInfo.USER_NAME +" TEXT," + TableData.TableInfo.USER_WEIGHT +" TEXT," + TableData.TableInfo.USER_GOAL +" TEXT," + TableData.TableInfo.USER_PASS +" TEXT," + TableData.TableInfo.USER_EMAIL +" TEXT);";
public DatabaseOperations(Context context) {
super(context, TableData.TableInfo.DATABASE_NAME, null, database_version);
Log.d("Database Operations", "Database Created");
}
@Override
public void onCreate(SQLiteDatabase sdb) {
sdb.execSQL(CREATE_QUERY);
Log.d("Database Operations", "Database Created");
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
}
public void putInformation(DatabaseOperations dop, String name, String pass, String email, String weight, String goal) {
SQLiteDatabase SQ = dop.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(TableData.TableInfo.USER_NAME, name);
cv.put(TableData.TableInfo.USER_PASS, pass);
cv.put(TableData.TableInfo.USER_EMAIL, email);
cv.put(TableData.TableInfo.USER_WEIGHT, weight);
cv.put(TableData.TableInfo.USER_GOAL, goal);
long k = SQ.insert(TableData.TableInfo.TABLE_NAME, null, cv);
Log.d("Database Operations", "One Raw Inserted");
}
public Cursor getInformation(DatabaseOperations dop){
SQLiteDatabase SQ = dop.getReadableDatabase();
String[] columns = {TableData.TableInfo.USER_NAME, TableData.TableInfo.USER_PASS, TableData.TableInfo.USER_EMAIL, TableData.TableInfo.USER_WEIGHT, TableData.TableInfo.USER_GOAL};
Cursor CR = SQ.query(TableData.TableInfo.TABLE_NAME, columns, null, null, null, null, null);
return CR;
}
}
答案 0 :(得分:0)
您需要关闭您打开的数据库...
DatabaseOperations mHelper = new DatabaseOperations(this);
SQLiteDatabase db = mHelper.getWritableDatabase();
//your other operation like cursor and adapter...
db.close();