采用Android HTTPGET / HttpPost使用ODBC数据库进行通信:有没有更快的方法? [英] using Android HttpGet/HttpPost to communicate with odbc database: is there a faster way?

查看:167
本文介绍了采用Android HTTPGET / HttpPost使用ODBC数据库进行通信:有没有更快的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个应用程序使用Android设备来获取和从Access数据库在局域网上设置的数据。我使用HttpPost和/或HTTPGET与这又与通过ODBC数据库通信的服务器上的PHP页面通信。

它运作良好,但需要几乎是第二为每个查询来完成。是否有一个更快的方法?

我通过USB实际设备上调试。当我从设备上的浏览器访问PHP页面,它的速度更快。有了这个网络上没有其他流量。

谢谢!

编辑:这里是code检索数据:

 私人JSONArray的getData(字符串phpFile,ArrayList的<&的NameValuePair GT; namevaluepairs中){ 字符串结果=;
 InputStream为= NULL;
 JSONArray jArray = NULL;尝试{   HttpClient的HttpClient的=新DefaultHttpClient();   HttpPost httppost =新HttpPost(HTTP://+ mServerIP +/ dressageNet /+ phpFile);   httppost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));   HTT presponse响应= httpclient.execute(httppost);   HttpEntity实体= response.getEntity();         是= entity.getContent();}赶上(例外五){
    Log.e(log_tag,在HTTP连接错误+ e.toString());
}尝试{    读者的BufferedReader =新的BufferedReader(新的InputStreamReader(是,ISO-8859-1),8);
    StringBuilder的SB =新的StringBuilder();
    串线= NULL;
    而((行= reader.readLine())!= NULL){
            sb.append(行+\\ n);}
    is.close();
    结果= sb.toString();}赶上(例外五){
    Log.e(log_tag,错误转换结果+ e.toString());
    }尝试{   jArray =新JSONArray(结果);}赶上(JSONException E){
   Log.e(log_tag,错误分析数据+ e.toString());
   }nameValuePairs.clear();
返回jArray;
}


解决方案

创建任何你想要的语言定制的服务器应用程序和停止使用HTTP服务器和PHP。 PHP是缓慢的,这造成的开销。当然,你需要实现自己的协议,但它会快很多。我做的Java ME这样的事情,而且表现方式不是做POST / GET更好。

I'm writing an app to use an Android device to get and set data from an Access database on a local area network. I'm using HttpPost and/or HttpGet to communicate with php pages on the server which in turn communicate with the db via odbc.

It works well, but takes almost a second for each query to complete. Is there a faster way?

I'm debugging via usb on the actual device. When I access the php pages from the browser on the device, it's much faster. There is no other traffic on this network.

Thanks!

Edit: Here's the code to retrieve a dataset:

private JSONArray getData(String phpFile,ArrayList<NameValuePair> nameValuePairs){

 String result = "";
 InputStream is = null;
 JSONArray jArray=null;

try{

   HttpClient httpclient = new DefaultHttpClient();

   HttpPost httppost = new HttpPost("http://" + mServerIP + "/dressageNet/"+ phpFile);

   httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 

   HttpResponse response = httpclient.execute(httppost); 

   HttpEntity entity = response.getEntity();

         is = entity.getContent();

}catch(Exception e){ 
    Log.e("log_tag", "Error in http connection "+e.toString());
}

try{

    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");}
    is.close();
    result=sb.toString();

}catch(Exception e){
    Log.e("log_tag", "Error converting result "+e.toString());
    }

try{

   jArray = new JSONArray(result);

}catch(JSONException e){
   Log.e("log_tag", "Error parsing data "+e.toString());
   }

nameValuePairs.clear();
return jArray;
}

解决方案

Create custom server application in whatever you language want and stop using http server and PHP. PHP is slow and this creates overhead. of course you will need to implement your own protocol but it will be a lot faster. I did something like this in java me, and performance was way better than doing POST/GET.

这篇关于采用Android HTTPGET / HttpPost使用ODBC数据库进行通信:有没有更快的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆