android读取数据,android读取数据线数据
android 怎么读取数据库中的数据
android读取数据库可以使用sqlite一些api进行读取,实例如下:
创新互联是专业的资兴网站建设公司,资兴接单;提供成都网站设计、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行资兴网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
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怎么直接获取数据库数据
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 怎样获取后台的数据?
可使用android自带的httpclient框架,向后台发起请求,获取数据。\x0d\x0a\x0d\x0a1. GET 方式传递参数\x0d\x0a//先将参数放入List,再对参数进行URL编码\x0d\x0aList params = new LinkedList();\x0d\x0aparams.add(new BasicNameValuePair("param1", "数据")); //增加参数1\x0d\x0aparams.add(new BasicNameValuePair("param2", "value2"));//增加参数2\x0d\x0aString param = URLEncodedUtils.format(params, "UTF-8");//对参数编码\x0d\x0aString baseUrl = "服务器接口完整URL";\x0d\x0aHttpGet getMethod = new HttpGet(baseUrl + "?" + param);//将URL与参数拼接\x0d\x0aHttpClient httpClient = new DefaultHttpClient();\x0d\x0atry {\x0d\x0a HttpResponse response = httpClient.execute(getMethod); //发起GET请求\x0d\x0a Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //获取响应码\x0d\x0a Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8"));//获取服务器响应内容\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方式 方式传递参数\x0d\x0a//和GET方式一样,先将参数放入List\x0d\x0aparams = new LinkedList();\x0d\x0aparams.add(new BasicNameValuePair("param1", "Post方法"));//增加参数1\x0d\x0aparams.add(new BasicNameValuePair("param2", "第二个参数"));//增加参数2\x0d\x0atry {\x0d\x0a HttpPost postMethod = new HttpPost(baseUrl);//创建一个post请求\x0d\x0a postMethod.setEntity(new UrlEncodedFormEntity(params, "utf-8")); //将参数填入POST Entity中\x0d\x0a HttpResponse response = httpClient.execute(postMethod); //执行POST方法\x0d\x0a Log.i(TAG, "resCode = " + response.getStatusLine().getStatusCode()); //获取响应码\x0d\x0a Log.i(TAG, "result = " + EntityUtils.toString(response.getEntity(), "utf-8")); //获取响应内容\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中在怎么获取数据库数据
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读取数据,android读取数据线数据
网站网址:http://cdiso.cn/article/dsggige.html