移动数据库位置
Moving location of a database
我找不到在我的应用程序中创建的数据库。
我在这里查看了其他类似的问题,我知道这可能是因为我没有 root 权限。
但是,我在 phone.
上找不到实际的应用程序文件夹
在模拟器的调试模式下,它在数据中,但我在安装 apk 时在 phone 上看不到它。
当我按下按钮时它没有给出任何错误,所以我假设数据库正在创建和可用。
问题是:有什么方法可以移动创建数据库的位置以便我可以看到它。
还有什么更好的方法可以增加数据库的数量吗?
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
}
}
如果你正在编写数据库操作,你应该有一个root设备或者你可以尝试使用Genymotion(预root)因为this.You可以看到你的db文件/data/data/com.yourpackage.com/databases/yourdb.db
。你可以很容易地看到db安装 RootExplorer 应用程序是否有数据。
我找不到在我的应用程序中创建的数据库。
我在这里查看了其他类似的问题,我知道这可能是因为我没有 root 权限。
但是,我在 phone.
上找不到实际的应用程序文件夹
在模拟器的调试模式下,它在数据中,但我在安装 apk 时在 phone 上看不到它。
当我按下按钮时它没有给出任何错误,所以我假设数据库正在创建和可用。
问题是:有什么方法可以移动创建数据库的位置以便我可以看到它。
还有什么更好的方法可以增加数据库的数量吗?
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
}
}
如果你正在编写数据库操作,你应该有一个root设备或者你可以尝试使用Genymotion(预root)因为this.You可以看到你的db文件/data/data/com.yourpackage.com/databases/yourdb.db
。你可以很容易地看到db安装 RootExplorer 应用程序是否有数据。