Android:访问数据库
我有以下代码:
DbAdapter dbAdapter = new DbAdapter(this);
dbAdapter.open();
ArrayList<String> queryResultList = new ArrayList<String>();
Cursor cur = dbAdapter.db.query("mytable", columns, where, null, groupBy, null, null);
cur.moveToFirst();
while (cur.isAfterLast() == false)
{
queryResultList.add(cur.getString(0));
cur.moveToNext();
}
cur.close();
dbAdapter.close();
该代码在以前从未运行过的设备上运行,即擦除的模拟器以及三星 Galaxy S 设备,其中该应用程序在第一次试用后被删除。这意味着我正在读取的数据库首先在设备上创建。它是一个自定义数据库。
在 2.2 上它运行得非常好,在 2.1-update1(API 级别 7)上它不会,isAfterLast() 总是 true,但它从 API 级别 1 开始就存在。有人有想法吗?或者我能做些什么来弄清楚?
谢谢,A.
I have the following code:
DbAdapter dbAdapter = new DbAdapter(this);
dbAdapter.open();
ArrayList<String> queryResultList = new ArrayList<String>();
Cursor cur = dbAdapter.db.query("mytable", columns, where, null, groupBy, null, null);
cur.moveToFirst();
while (cur.isAfterLast() == false)
{
queryResultList.add(cur.getString(0));
cur.moveToNext();
}
cur.close();
dbAdapter.close();
This code runs on a device where it never run before, i.e. a wiped emulator as well as a Samsung Galaxy S device where the app was removed after the first trial. That means the database I am reading is being created first on the device. It is a custom database.
On 2.2 it runs perfectly fine, on 2.1-update1 (API Level 7) it wont, the isAfterLast() is always true, but it is there since API Level 1. Any one an idea? Or an idea what I can do to figure out?
Thanks, A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,为什么不使用:
Hmm, why not use: