我找不到在我的应用程序中创建的数据库 我在这里看了其他类似的问题,我知道这可能是因为我没有root权限 但是,我在手机上找不到实际的app文件夹 在模拟器上的调试模式下它是数据,但是当我安装apk时,我无法在手机上看到它 当我按下Buttons时它没有出错,因此我假设db正在创建并可用。
问题是:有没有办法移动创建数据库的位置,以便我可以看到它 还有什么更好的方法来增加数据库的数量?
package com.example.a2618436.customersatsifaction;
/**
* Created by 2618436 on 06/05/2016.
*/
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
public class MyDBHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "SurveyDB.db";
private static final String TABLE_SURVEY = "Survey";
public static final String KEY_ID= "id";
public static final String KEY_HAPPY = "happy";
public static final String KEY_SAD = "sad";
public MyDBHandler(Context context, String name,
SQLiteDatabase.CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db){
String CREATE_SURVEY_TABLE = "CREATE TABLE " +
TABLE_SURVEY + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_HAPPY
+ " INTEGER," + KEY_SAD + " INTEGER" + ")";
db.execSQL(CREATE_SURVEY_TABLE);
}
//
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion){
db.execSQL("DROP TABLE IF EXISTS " + TABLE_SURVEY);
onCreate(db);
}
//needs revision
public void addSurvey(MainActivity mainactivity) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_HAPPY, mainactivity.getHappy()); // Contact Name
values.put(KEY_SAD, mainactivity.getSad()); // Contact Phone Number
// Inserting Row
db.insert(TABLE_SURVEY, null, values);
db.close(); // Closing database connection
}
}
数据库处理程序。
package com.example.a2618436.customersatsifaction;
/**
* Created by 2618436 on 06/05/2016.
*/
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
public class MyDBHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "SurveyDB.db";
private static final String TABLE_SURVEY = "Survey";
public static final String KEY_ID= "id";
public static final String KEY_HAPPY = "happy";
public static final String KEY_SAD = "sad";
public MyDBHandler(Context context, String name,
SQLiteDatabase.CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db){
String CREATE_SURVEY_TABLE = "CREATE TABLE " +
TABLE_SURVEY + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_HAPPY
+ " INTEGER," + KEY_SAD + " INTEGER" + ")";
db.execSQL(CREATE_SURVEY_TABLE);
}
//
public void onUpgrade(SQLiteDatabase db, int oldVersion,
int newVersion){
db.execSQL("DROP TABLE IF EXISTS " + TABLE_SURVEY);
onCreate(db);
}
//needs revision
public void addSurvey(MainActivity mainactivity) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_HAPPY, mainactivity.getHappy()); // Contact Name
values.put(KEY_SAD, mainactivity.getSad()); // Contact Phone Number
// Inserting Row
db.insert(TABLE_SURVEY, null, values);
db.close(); // Closing database connection
}
}
答案 0 :(得分:0)
如果你正在编写数据库操作,你应该有一个root设备,或者你可以为此尝试Genymotion(pre rooted)。你可以看到你的db文件/data/data/com.yourpackage.com/databases/yourdb.db
。你可以很容易地看到db有数据吗?安装RootExplorer app。