Android 将sqlitedatabase中的文件放在我们的应用程序中的何处
我为数据库创建了一个应用程序,其中包含一个student表和3个字段,但我不知道如何将应用程序中的文件添加到Android 将sqlitedatabase中的文件放在我们的应用程序中的何处,android,database,sqlite,android-layout,Android,Database,Sqlite,Android Layout,我为数据库创建了一个应用程序,其中包含一个student表和3个字段,但我不知道如何将应用程序中的文件添加到sqlite数据库中 数据库帮助程序: public class DatabaseHelper extends SQLiteOpenHelper { public static final String DATA_BASE="Mydatabase.db"; public static final String TABLE_NAME="Student"; public static
sqlite数据库中
数据库帮助程序:
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATA_BASE="Mydatabase.db";
public static final String TABLE_NAME="Student";
public static final int DATABASE_VERSION =1;
public DatabaseHelper(Context context) {
super(context, DATA_BASE, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME +
"(Name TEXT, AGE NUMERIC, ADDRESS TEXT)"); }
@Override
public void onUpgrade(SQLiteDatabase db,
int oldVersion, int newVersion) {
}
}
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATA_BASE="Mydatabase.db";
public static final String TABLE_NAME="Student";
public static final int DATABASE_VERSION =1;
public DatabaseHelper(Context context) {
super(context, DATA_BASE, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME +
"(Name TEXT, AGE NUMERIC, ADDRESS TEXT)"); }
@Override
public void onUpgrade(SQLiteDatabase db,
int oldVersion, int newVersion) {
}
}
public class DisplayActivity extends Activity {
private ArrayList<String> arrayList =
new ArrayList<String>();
private SQLiteDatabase Mydatabase;
ListView listView;
EditText enter;
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.display);
listView=(ListView)findViewById(R.id.listView);
//OpenAndQueryDatabase
try {
DatabaseHelper db = new DatabaseHelper(this);
//Open the database
Mydatabase = db.getWritableDatabase();
Cursor c = Mydatabase.rawQuery(
"SELECT * FROM Student", null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String Name = c.getString(
c.getColumnIndex("Name"));
int age = c.getInt(
c.getColumnIndex("AGE"));
String address = c.getString(
c.getColumnIndex("ADDRESS"));
arrayList.add("Name : " + Name +"\n"+
"Age : " +age +"\n"+
"Address : " + address+"\n");
}while (c.moveToNext());
}
}
} catch (SQLiteException se ) { }
finally {
if (Mydatabase != null)
Mydatabase.close();
}
//displayResultList
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
arrayList));
}
}
主要活动:
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATA_BASE="Mydatabase.db";
public static final String TABLE_NAME="Student";
public static final int DATABASE_VERSION =1;
public DatabaseHelper(Context context) {
super(context, DATA_BASE, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME +
"(Name TEXT, AGE NUMERIC, ADDRESS TEXT)"); }
@Override
public void onUpgrade(SQLiteDatabase db,
int oldVersion, int newVersion) {
}
}
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATA_BASE="Mydatabase.db";
public static final String TABLE_NAME="Student";
public static final int DATABASE_VERSION =1;
public DatabaseHelper(Context context) {
super(context, DATA_BASE, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME +
"(Name TEXT, AGE NUMERIC, ADDRESS TEXT)"); }
@Override
public void onUpgrade(SQLiteDatabase db,
int oldVersion, int newVersion) {
}
}
public class DisplayActivity extends Activity {
private ArrayList<String> arrayList =
new ArrayList<String>();
private SQLiteDatabase Mydatabase;
ListView listView;
EditText enter;
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.display);
listView=(ListView)findViewById(R.id.listView);
//OpenAndQueryDatabase
try {
DatabaseHelper db = new DatabaseHelper(this);
//Open the database
Mydatabase = db.getWritableDatabase();
Cursor c = Mydatabase.rawQuery(
"SELECT * FROM Student", null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String Name = c.getString(
c.getColumnIndex("Name"));
int age = c.getInt(
c.getColumnIndex("AGE"));
String address = c.getString(
c.getColumnIndex("ADDRESS"));
arrayList.add("Name : " + Name +"\n"+
"Age : " +age +"\n"+
"Address : " + address+"\n");
}while (c.moveToNext());
}
}
} catch (SQLiteException se ) { }
finally {
if (Mydatabase != null)
Mydatabase.close();
}
//displayResultList
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
arrayList));
}
}
显示活动:
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATA_BASE="Mydatabase.db";
public static final String TABLE_NAME="Student";
public static final int DATABASE_VERSION =1;
public DatabaseHelper(Context context) {
super(context, DATA_BASE, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME +
"(Name TEXT, AGE NUMERIC, ADDRESS TEXT)"); }
@Override
public void onUpgrade(SQLiteDatabase db,
int oldVersion, int newVersion) {
}
}
public class DatabaseHelper extends SQLiteOpenHelper {
public static final String DATA_BASE="Mydatabase.db";
public static final String TABLE_NAME="Student";
public static final int DATABASE_VERSION =1;
public DatabaseHelper(Context context) {
super(context, DATA_BASE, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME +
"(Name TEXT, AGE NUMERIC, ADDRESS TEXT)"); }
@Override
public void onUpgrade(SQLiteDatabase db,
int oldVersion, int newVersion) {
}
}
public class DisplayActivity extends Activity {
private ArrayList<String> arrayList =
new ArrayList<String>();
private SQLiteDatabase Mydatabase;
ListView listView;
EditText enter;
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.display);
listView=(ListView)findViewById(R.id.listView);
//OpenAndQueryDatabase
try {
DatabaseHelper db = new DatabaseHelper(this);
//Open the database
Mydatabase = db.getWritableDatabase();
Cursor c = Mydatabase.rawQuery(
"SELECT * FROM Student", null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String Name = c.getString(
c.getColumnIndex("Name"));
int age = c.getInt(
c.getColumnIndex("AGE"));
String address = c.getString(
c.getColumnIndex("ADDRESS"));
arrayList.add("Name : " + Name +"\n"+
"Age : " +age +"\n"+
"Address : " + address+"\n");
}while (c.moveToNext());
}
}
} catch (SQLiteException se ) { }
finally {
if (Mydatabase != null)
Mydatabase.close();
}
//displayResultList
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
arrayList));
}
}
公共类DisplayActivity扩展活动{
专用ArrayList ArrayList=
新的ArrayList();
私有SQLiteDatabase-Mydatabase;
列表视图列表视图;
编辑文本输入;
@凌驾
创建时的公共void(Bundle b){
super.onCreate(b);
setContentView(R.layout.display);
listView=(listView)findViewById(R.id.listView);
//OpenAndQueryDatabase
试一试{
DatabaseHelper db=新的DatabaseHelper(此);
//打开数据库
Mydatabase=db.getWritableDatabase();
游标c=Mydatabase.rawQuery(
“从学生中选择*”,空);
如果(c!=null){
if(c.moveToFirst()){
做{
String Name=c.getString(
c、 getColumnIndex(“名称”);
int age=c.getInt(
c、 指数("年龄);;
字符串地址=c.getString(
c、 getColumnIndex(“地址”);
arrayList.add(“名称:”+Name+“\n”+
年龄:“+Age+”\n+
“地址:“+地址+”\n”);
}而(c.moveToNext());
}
}
}catch(SQLiteException se){}
最后{
if(Mydatabase!=null)
Mydatabase.close();
}
//显示结果列表
setAdapter(新的ArrayAdapter(此,
android.R.layout.simple\u list\u item\u 1,
arrayList);
}
}
您可以找到您的答案。只需在SD卡中的某个位置创建一个文件
数据/文件夹受操作系统保护,只有根设备才能看到它
您需要的是链接的答案:使用新文件(“/SDCARD/myFolder/myFile.sqlite”)打开SD卡中的文件
通过执行以下操作,可以将数据库从emulator中拉出来查看
1) 转到Eclipse中的DDMS屏幕。
2) 打开名为“文件资源管理器”的选项卡
3) 导航到包含数据库的目录(通常是data\data\your.package.name\databases
)
4) 突出显示/选择您的数据库文件
5) 在右上角单击图标,箭头指向右侧“从设备中拉出文件”
6) 按照提示将文件保存到计算机。
7) 使用您选择的SQLite数据库浏览器打开文件
编辑
注意这只适用于模拟器上的数据。。。它不会从真实设备中提取数据库,因为真实设备上的数据
目录在应用程序外部受保护/不可访问。在eclipse中,转到windows->Showview->android->File Explorer
在那里你可以在这里看到你的数据库/data/data/yourpackage/database
使用右角的按钮从那个里拉出你们的数据库。
使用此Firefox add查看您的数据。:但我正在使用eclipse开发应用程序…我找不到数据/数据//数据库/路径…因此我被困在这里如何查看插入sqlite数据库中的Emmolator中的日期我不太清楚您想要什么。。。您的代码显示您正在创建一个空数据库。。。但是你说你想复制一个文件。。。你是否在应用程序外部创建了数据库,现在想将其加载并在应用程序中使用?否…我创建了我的应用程序..我想在SQLite数据库中查看它。我在应用程序运行时将数据插入Emmolator..并且我在列表视图的另一个页面中获取输入的所有数据..现在我想查看在SQLite数据库中输入的数据:非常感谢…可以吗您还可以告诉我的应用程序的代码,以便我可以添加基于关键字的搜索选项MOST welcome。检查此链接。您还可以告诉我在键入edittextmEdit=(EditText)findViewById(R.id.EditText)时如何将编辑文本值设置为字符串吗;mButton.setOnClickListener(new View.OnClickListener(){public void onClick(视图视图){Log.v(“EditText”,mEdit.getText().toString());});它将如何分配给某个字符串对象?