1
我正在編寫一個應用程序,以使用Android設備從局域網上的Access數據庫獲取和設置數據。我使用HttpPost和/或HttpGet與服務器上的php頁面進行通信,並通過odbc與db進行通信。:有更快的方法嗎?
它運行良好,但每個查詢需要幾乎一秒的時間才能完成。有更快的方法嗎?
我正在通過USB在實際設備上進行調試。當我從設備上的瀏覽器訪問php頁面時,速度會更快。此網絡上沒有其他流量。
謝謝!
編輯:下面是檢索數據集的代碼:
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;
}
如果您發佈了一些代碼,它會告訴我們您是如何實際使用get/post方法,這會更容易。也許在目前的狀態下,有一些開銷並不明顯。 – darioo