我找不到在我的应用程序中创建的数据库。
我看过其他类似的问题,我知道这可能是因为我没有root权限。
但是,我找不到手机上的实际应用程序文件夹。
在模拟器上的调试模式下,它在数据中,但我安装apk时无法在手机上看到它。
当我按下按钮时,它不会给出任何错误,所以我假设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
}
}
为什么你需要访问设备上的数据库?你可以在DDMS中检查它(请考虑在仿真器上开发,而不是在物理设备上开发 - 这是最糟糕的实践)。 –
** 1 ** - 如果您愿意,您可以在存储上创建数据库。然后你会受到欺骗。 ** 2 ** - 你是什么意思'也有更好的方法来增加数据库上的数字吗? –
我无法在模拟器上找到数据库,所以我不认为它实际上已经创建。它不在com.example文件夹中,我认为它应该是。 – user3603437