开发者

using Android HttpGet/HttpPost to communicate with odbc database: is there a faster way?

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 ther开发者_如何转开发e 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜