数据库的查询语句
在Anroid中查詢從數據庫調用的數據,用到getString()方法;例如
1.先創建一個數據庫
FruitInfoHelper helper=new FruitInfoHelper();
2.先獲取一個可讀寫的數據庫
SQLiteDatabase db=helper.getWritableDatabase();
3.使用query()方法返回游標Cursor
Cursor cursor=db.query("FruitInfo",null,"fname=?",new String[]{name},null,null,null);
4.判斷是否有下一個信息用moveToNext()方法
while(cursor.moveToNext()){
String n=cursor.getString(cursor.getColumnIndex("fname"));
float ?p=cursor.getFloat(cursor.getColumnIndex("fprice"));
System.out.println(n+" "+f);
}
cursor.close();
db.close();
轉載于:https://www.cnblogs.com/creazybeauty/p/6001781.html
總結
- 上一篇: 理解 neutron(15):Neutr
- 下一篇: MySQL学习_计算用户支付方式占比_2