开发者

Android : query with date

I must to do a que开发者_如何学Gory but I have a problem with date becase the structure is 27/08/2011 this is the code :

dt="27/08/2011";
db.query(TABLE,null,mydata + "=" + dt,null,null,null,null);

the problem is that the cursor is always 0. I think that is the data structure because if I query other it work fine


Your date isn't quoted so SQLite will interpret 27/08/2011 as a mathematical expression and replace it with 0 (the integer value of 27 divided by 8 divided by 2011). You could quote it yourself:

db.query(TABLE, null, mydata + "=" + "'" + dt + "'", null, null, null, null);

Or better, use a placeholder:

db.query(TABLE, null, mydata + "= ?", new String[] { dt }, null, null, null);

Switching to an ISO 8601 date format would also be a good idea to avoid possible locale-based ambiguity in the date:

String dt = "2011/08/27";
Cursor c  = db.query(TABLE, null, mydata + "= ?", new String[] { dt }, null, null, null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜