将数据库推送到 root 设备
我正在尝试访问我的设备上的数据/文件夹,但无法打开它?..我已经root了我的手机,我想将我的数据库推送到我的设备上的数据库文件夹,以便我可以运行我开发的应用程序,它在模拟器上运行良好,但我想在真实设备上测试它,但它没有获取数据库。
我使用 SQLite 管理器创建了包含记录的数据库,然后在模拟器上使用 DDMS 推送它。我尝试使用代码插入记录,但每当应用程序启动时,它都会不断插入相同的记录,有没有办法只插入这些记录一次?
这是我在 DBHelper 类中的插入代码:
public void inserttable1Contact(String a, String b){
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_a, a);
initialValues.put(KEY_b, b);
db.insert(DATABASE_TABLE1, null, initialValues);}
然后我在我的主类中调用它:
db.inserttable1Contact("aa", "bb");
我已经做了很多搜索,但找不到任何有用的答案。 请帮忙,非常紧急。
谢谢
I'm trying to access the data/ folder on my device I cant get it to open?..I've rooted my phone and I want to push my database to the database folder on my device so that I can run my developed app, it works fine on the emulator but I want to test it on a real device and its not getting the database.
I created my database with records using SQLite manager then I pushed it using DDMS on emulator. I tried inserting records using code but whenever the app starts it keeps inserting the same records is there a way to insert these record only once?
this is my insert code in DBHelper class:
public void inserttable1Contact(String a, String b){
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_a, a);
initialValues.put(KEY_b, b);
db.insert(DATABASE_TABLE1, null, initialValues);}
and then I call it in my main class:
db.inserttable1Contact("aa", "bb");
I've done a lot of searching but couldn't find any useful answers.
Any help please, its very urgent.
Thanx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,您会在 SQLiteOpenHelper 中重写
onCreate
来插入初始数据。由于您是通过侧面加载来创建数据库的,因此我建议使用某种持久存储(例如,共享首选项,或数据库中的单独单行表)来保存一个标志,表明该数据库已被用数据初始化。如果未设置该标志(并设置该标志),则仅调用inserttable1Contact
。Normally you would override
onCreate
in your SQLiteOpenHelper to insert initial data. Since you're creating the data base by side-loading it, I suggest using some sort of persistent storage (e.g., shared prefs, or a separate, one-row table in the db) to save a flag indicating that the db has been initialized with data. Then only callinserttable1Contact
if that flag is not set (and set the flag).