android读取数据库可以使用sqlite一些api进行读取,实例如下:
/*** 查找一条数据
* @param uid
*/
public User find(Integer uid){
SQLiteDatabase db=dbOpenHelper.getReadableDatabase() //创建数据库辅助类
Cursor cursor =db.rawQuery("select * from user where uid=?", new String[]{uid.toString()}) //创建一个游标
if(cursor.moveToFirst()){ //循环遍历查找数组
int uid2=cursor.getInt(cursor.getColumnIndex("uid"))
String uname=cursor.getString(cursor.getColumnIndex("uname"))
String uaddress=cursor.getString(cursor.getColumnIndex("uaddress"))
User user=new User()
user.setUid(uid2)
user.setUname(uname)
user.setUaddress(uaddress)
return user
}
cursor.close()
return null
}
android读取数据库可以使用sqlite一些api进行读取,实例如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* 查找一条数据
* @param uid
*/
public User find(Integer uid){
SQLiteDatabase db=dbOpenHelper.getReadableDatabase() //创建数据库辅助类
Cursor cursor =db.rawQuery("select * from user where uid=?", new String[]{uid.toString()}) //创建一个游标
if(cursor.moveToFirst()){ //循环遍历查找数组
int uid2=cursor.getInt(cursor.getColumnIndex("uid"))
String uname=cursor.getString(cursor.getColumnIndex("uname"))
String uaddress=cursor.getString(cursor.getColumnIndex("uaddress"))
User user=new User()
user.setUid(uid2)
user.setUname(uname)
user.setUaddress(uaddress)
return user
}
cursor.close()
return null
}
android读取数据库可以使用sqlite一些api进行读取,实例如下:/**
* 查找一条数据
* @param uid
*/
public User find(Integer uid){
SQLiteDatabase db=dbOpenHelper.getReadableDatabase() //创建数据库辅助类
Cursor cursor =db.rawQuery("select * from user where uid=?", new String[]{uid.toString()}) //创建一个游标
if(cursor.moveToFirst()){ //循环遍历查找数组
int uid2=cursor.getInt(cursor.getColumnIndex("uid"))
String uname=cursor.getString(cursor.getColumnIndex("uname"))
String uaddress=cursor.getString(cursor.getColumnIndex("uaddress"))
User user=new User()
user.setUid(uid2)
user.setUname(uname)
user.setUaddress(uaddress)
return user
}
cursor.close()
return null
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)