码迷,mamicode.com
首页 > 数据库 > 详细

sqlite查询

时间:2015-10-27 20:16:42      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:

private static final String TABLENAME = "mytab";
 private SQLiteDatabase db = null;

 public Qu(SQLiteDatabase db) {
  this.db = db;
 }

 public List<String> find() {
  List<String> all = new ArrayList<String>();
  String sql = "select id,name,birthday from mytab";
   Cursor result = db.rawQuery(sql, null);

                     从第一个开始查            不是最后一个            移动到下一个
   for (result.moveToFirst(); !result.isAfterLast(); result.moveToNext())
   {
   all.add(result.getInt(0)+result.getString(1)+result.getString(2));
   }
   db.close();

return all;

}

  List<String> all = new ArrayList<String>();

 String[] da ={"id","name","birthday"};
  Cursor result = db.query(TABLENAME, da, null, null, null, null,null);
   for (result.moveToFirst(); !result.isAfterLast(); result.moveToNext())
   {
   all.add(result.getInt(0)+result.getString(1)+result.getString(2));
   }
   db.close();

return all;

 

 String sql = "select id,name,birthday from mytab where name like ? or birthday like ?";
  String keyword = "5";
  String[] args = new String[] { "%" + keyword + "%", "%" + keyword + "%" };
  Cursor result = db.rawQuery(sql, args);
  for (result.moveToFirst(); !result.isAfterLast(); result.moveToNext()) {
   all.add(result.getInt(0) + result.getString(1)
     + result.getString(2));
  }
  return all;

sqlite查询

标签:

原文地址:http://www.cnblogs.com/84126858jmz/p/4915244.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!