查询该怎么做呢?
查询。。
查询。。
2017-02-23
也有两种方法,跟视屏中的类似,也有封装好的api方法,只要填相应的字段,也可以自己写。比如:
public void onClick(View v) { SQLiteDatabase db = dbHelper.getWritableDatabase(); //查询Book表中的所有数据,后面的都为null表示查找所有数据,没有条件,这种是封装好的api方法 Cursor cursor = db.query("Book", null, null, null, null, null, null); if (cursor.moveToFirst()) { do { //遍历Cursor对象,取出数据并打印 String name = cursor.getString(cursor.getColumnIndex("name")); String author = cursor.getString(cursor.getColumnIndex("author")); int pages = cursor.getInt(cursor.getColumnIndex("pages")); Double price = cursor.getDouble(cursor.getColumnIndex("price")); Log.d(TAG, "book name is " + name); Log.d(TAG, "book author is " + author); Log.d(TAG, "book pages is " + pages); Log.d(TAG, "book price is " + price); } while (cursor.moveToNext()); } cursor.close(); }
举报