Android - 关闭数据库后可以使用SQLite Cursor吗? [英] Android - Can SQLite Cursor's be used after closing the database?

查看:163
本文介绍了Android - 关闭数据库后可以使用SQLite Cursor吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,如果我错了,请纠正我,但是如果你关闭了数据库连接,就不能使用你从中得到的光标,对吗?

First of all, correct me if I'm wrong, but if you close a database connection, you can't use the Cursor you got from it, correct?

db.open();
Cursor c = db.query(true, "MyTable", columns, null, null, null, null, null, null);
db.close();

// The Cursor is empty now because the db was closed...
c.moveToNext();
Log.v(TAG, c.toString(0));

那么在关闭数据库之后有没有办法使用Cursor?就像有没有办法将它传递到别处并使用它有点像一个对象?或者你总是要打开数据库连接,直到完成光标?

So is it there any way to use the Cursor after closing the database? Like is there any way to pass it elsewhere and use it kinda like an object? Or do you always have to leave the database connection open until you are done with the cursor?

推荐答案

不,正如它所说的那样如果你关闭数据库,下面的链接,光标将变为无效。

No, As it says in the link below, if you close the database, the cursor becomes invalid.

数据库关闭后光标是否仍然存在?

这篇关于Android - 关闭数据库后可以使用SQLite Cursor吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆