关于安卓通过webservice访问数据库问题

发表于:2014-12-10 10:30

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:android开发教程2015    来源:51Testing软件测试网采编

  ============问题描述============
  访问数据库时,手机能增删数据库的数据就是显示不了数据库的里的数据不知道是哪里的问题,用的HTTP
  这是我webservice中的产看所有信息的方法:
public List<string> selectAllCargoInfor()
{
List<string> list = new List<string>();
try
{
string sql = "select * from C";
SqlCommand cmd = new SqlCommand(sql,sqlCon);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
//将结果集信息添加到返回向量中
list.Add(reader[0].ToString());
list.Add(reader[1].ToString());
list.Add(reader[2].ToString());
}
reader.Close();
cmd.Dispose();
}
catch(Exception)
{
}
return list;
}
  接下来是安卓端的:
  这个是MainActivity中的设置LISTVIEW的方法
private void setListView() {
listView.setVisibility(View.VISIBLE);
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
list = dbUtil.getAllInfo();
adapter = new SimpleAdapter(MainActivity.this, list, R.layout.adapter_item,
new String[] { "Cno", "Cname", "Cnum" },
new int[] { R.id.txt_Cno, R.id.txt_Cname, R.id.txt_Cnum });
listView.setAdapter(adapter);
}
  这个是操作类:
public List<HashMap<String, String>> getAllInfo() {
List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
arrayList.clear();
brrayList.clear();
crrayList.clear();
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
crrayList = Soap.GetWebServre("selectAllCargoInfor", arrayList, brrayList);
}
}).start();
HashMap<String, String> tempHash = new HashMap<String, String>();
tempHash.put("Cno", "Cno");
tempHash.put("Cname", "Cname");
tempHash.put("Cnum", "Cnum");
list.add(tempHash);
for (int j = 0; j < crrayList.size(); j += 3) {
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("Cno", crrayList.get(j));
hashMap.put("Cname", crrayList.get(j + 1));
hashMap.put("Cnum", crrayList.get(j + 2));
list.add(hashMap);
}
return list;
}
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号