android sqlite 项目
大家好,我有这个 android sqlite 代码来读取表中的所有标题,该代码位于 DBHelper.java 中
//---retrieves all the titles---
public Cursor getAllTitles()
{
return db.query(DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_BOOK,
KEY_AUTHOR,
KEY_EDITION,
KEY_YEAR,
KEY_RETURNDATE},
null,
null,
null,
null,
null);
,这是我的主应用程序中的代码......
//---get all titles---
db.open();
Cursor c = db.getAllTitles();
if (c.moveToFirst())
{
do {
DisplayTitle(c);
} while (c.moveToNext());
}
我的问题是我想获取例如返回日期,以便我可以将其与当前时间进行比较,并基于此我将采取行动
,以便我可以读取它..buffer[5]并比较它....???
hi to all i have this android sqlite code to read all the titles from a table and this code is in the DBHelper.java
//---retrieves all the titles---
public Cursor getAllTitles()
{
return db.query(DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_BOOK,
KEY_AUTHOR,
KEY_EDITION,
KEY_YEAR,
KEY_RETURNDATE},
null,
null,
null,
null,
null);
and this is the code in my main app.....
//---get all titles---
db.open();
Cursor c = db.getAllTitles();
if (c.moveToFirst())
{
do {
DisplayTitle(c);
} while (c.moveToNext());
}
my question is that i want to get for example the returendate so i can compare it to the current time and based on that i will make an action
so can i read it ....buffer[5] and compare it....???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
假设您的返回日期是一个字符串,您可以在 DisplayTitle(cursor c) 中使用以下内容:
Assuming your return date is a string, you can use the following in your DisplayTitle(cursor c) :
使用
c.getString(c.getColumnIndex(KEY_RETURNDATE));
正如 rajath 所说,如果不再需要它,请不要忘记在循环后关闭游标:c .close();
否则将会出现内存泄漏。Use
c.getString(c.getColumnIndex(KEY_RETURNDATE));
as rajath said, and don't forget to close your Cursor after your loop if you don't need it any more:c.close();
else you will have a memory leak.