android讀取數(shù)據(jù)庫可以使用sqlite一些api進(jìn)行讀取,實例如下:

創(chuàng)新互聯(lián)是專業(yè)的資興網(wǎng)站建設(shè)公司,資興接單;提供成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè),網(wǎng)頁設(shè)計,網(wǎng)站設(shè)計,建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行資興網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊,希望更多企業(yè)前來合作!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/**
* 查找一條數(shù)據(jù)
* @param uid
*/
public User find(Integer uid){
SQLiteDatabase db=dbOpenHelper.getReadableDatabase(); //創(chuàng)建數(shù)據(jù)庫輔助類
Cursor cursor =db.rawQuery("select * from user where uid=?", new String[]{uid.toString()}); //創(chuàng)建一個游標(biāo)
if(cursor.moveToFirst()){ //循環(huán)遍歷查找數(shù)組
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讀取數(shù)據(jù)庫可以使用sqlite一些api進(jìn)行讀取,實例如下:
/**
* 查找一條數(shù)據(jù)
* @param uid
*/
public User find(Integer uid){
SQLiteDatabase db=dbOpenHelper.getReadableDatabase(); //創(chuàng)建數(shù)據(jù)庫輔助類
Cursor cursor =db.rawQuery("select * from user where uid=?", new String[]{uid.toString()}); //創(chuàng)建一個游標(biāo)
if(cursor.moveToFirst()){ //循環(huán)遍歷查找數(shù)組
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自帶的httpclient框架,向后臺發(fā)起請求,獲取數(shù)據(jù)。\x0d\x0a\x0d\x0a1. GET 方式傳遞參數(shù)\x0d\x0a//先將參數(shù)放入List,再對參數(shù)進(jìn)行URL編碼\x0d\x0aList params = new LinkedList();\x0d\x0aparams.add(new BasicNameValuePair("param1", "數(shù)據(jù)")); //增加參數(shù)1\x0d\x0aparams.add(new BasicNameValuePair("param2", "value2"));//增加參數(shù)2\x0d\x0aString param = URLEncodedUtils.format(params, "UTF-8");//對參數(shù)編碼\x0d\x0aString baseUrl = "服務(wù)器接口完整URL";\x0d\x0aHttpGet getMethod = new HttpGet(baseUrl + "?" + param);//將URL與參數(shù)拼接\x0d\x0aHttpClient httpClient = new DefaultHttpClient();\x0d\x0atry {\x0d\x0a HttpResponse response = httpClient.execute(getMethod); //發(fā)起GET請求\x0d\x0a Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //獲取響應(yīng)碼\x0d\x0a Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8"));//獲取服務(wù)器響應(yīng)內(nèi)容\x0d\x0a} catch (ClientProtocolException e) {\x0d\x0a e.printStackTrace();\x0d\x0a} catch (IOException e) {\x0d\x0a e.printStackTrace();\x0d\x0a}\x0d\x0a\x0d\x0a2. POST方式 方式傳遞參數(shù)\x0d\x0a//和GET方式一樣,先將參數(shù)放入List\x0d\x0aparams = new LinkedList();\x0d\x0aparams.add(new BasicNameValuePair("param1", "Post方法"));//增加參數(shù)1\x0d\x0aparams.add(new BasicNameValuePair("param2", "第二個參數(shù)"));//增加參數(shù)2\x0d\x0atry {\x0d\x0a HttpPost postMethod = new HttpPost(baseUrl);//創(chuàng)建一個post請求\x0d\x0a postMethod.setEntity(new UrlEncodedFormEntity(params, "utf-8")); //將參數(shù)填入POST Entity中\(zhòng)x0d\x0a HttpResponse response = httpClient.execute(postMethod); //執(zhí)行POST方法\x0d\x0a Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //獲取響應(yīng)碼\x0d\x0a Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8")); //獲取響應(yīng)內(nèi)容\x0d\x0a} catch (UnsupportedEncodingException e) {\x0d\x0a e.printStackTrace();\x0d\x0a} catch (ClientProtocolException e) {\x0d\x0a e.printStackTrace();\x0d\x0a} catch (IOException e) {\x0d\x0a e.printStackTrace();\x0d\x0a}
android讀取數(shù)據(jù)庫可以使用sqlite一些api進(jìn)行讀取,實例如下:
/**
* 查找一條數(shù)據(jù)
* @param uid
*/
public User find(Integer uid){
SQLiteDatabase db=dbOpenHelper.getReadableDatabase(); //創(chuàng)建數(shù)據(jù)庫輔助類
Cursor cursor =db.rawQuery("select * from user where uid=?", new String[]{uid.toString()}); //創(chuàng)建一個游標(biāo)
if(cursor.moveToFirst()){ //循環(huán)遍歷查找數(shù)組
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;
}
網(wǎng)頁題目:android讀取數(shù)據(jù),android讀取數(shù)據(jù)線數(shù)據(jù)
分享鏈接:http://chinadenli.net/article14/dsggige.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、App開發(fā)、做網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)、用戶體驗、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)