问题描述
我使用 android studio 创建了一个名为 "company"
的数据库.当我想查看我创建的数据库时,我找不到它.
I have created a database named "company"
using android studio. When I want to view the database I created, I can't find it.
我按照下面的步骤
Open DDMS via Tools > Android > Android Device Monitor
并在左侧看到我的项目名称.
and see my project name on the left.
但是,当我转到文件资源管理器,转到/data/data/com.example.project.project 时,我没有看到创建的数据库应该在数据库包下.那里只有两个文件夹,一个是cache
,另一个是code_cache.
我错过了哪些步骤?希望有人可以帮助我找出问题所在.谢谢
However, when I go to File Explorer,go to /data/data/com.example.project.project, I didn't see the database created which should under database package. There only have two folder there, one is cache
and another is code_cache.
What steps I have missed out? Hope someone can help me to figuring out the problem. Thanks
MyDataBaseHelper.java
package com.example.project.project.database;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class MyDatabaseHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION=1;
public static final String DATABASE_NAME="Company.db";
public final static String TABLE_NAME="TimeSheet";
public static final String ID="id";
public static final String Name="name";
public static final String Weather="weather";
// public static final String DATABASE_CREATE_TIME_SHEET="create table"+TABLE_NAME+"(+ Name+"TEXT,"+ Weather+"TEXT)";
public void onCreate(SQLiteDatabase db)
{
db.execSQL("create table "+TABLE_NAME+"(name text,weather text)");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion,int newVersion)
{
Log.w(MyDatabaseHelper.class.getName(),"Upgrading database from version"+oldVersion+"to"+newVersion+",which will destroy all old data");
db.execSQL("Drop TABLE IF EXISTS "+TABLE_NAME);
onCreate(db);
}
public MyDatabaseHelper(Context context)
{
super(context, DATABASE_NAME,null,1);
}
}
推荐答案
错过了这个
database=dbHelper.getWritableDatabase();
这篇关于在android studio中查看sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!