从SQLite中提取数据并插入到远程数据库


Extracting data from SQLite and inserting to remote database

好吧,计算机科学新手,不知怎么的。

我的讲师说,如果我们能在应用程序上实现远程数据库,那么它将大大提高我们的分数。我们有4天的时间,只有我和另外两个人。。

据我所知:

  1. 数据必须从SQLlite数据库中提取,作为JSON或XML
  2. 数据必须通过HTTP发送到我们的远程服务器,因此我们需要将我们的数据库与远程服务器连接
  3. 在将数据插入mySQL之前,必须对其进行解析远程服务器中的表

即使android使用XML,我认为如果使用JSON也没有什么区别?以前用PHP解析过数据并连接到服务器,但对java不太熟悉。

我们非常感谢任何关于该主题的资源或教程,我们正在努力尝试,并意识到我们将遇到数百万困难,因此希望在尽可能长的时间内取得尽可能多的进展。欢迎提供任何信息。

感谢

很抱歉我可能没有完全理解你的问题,但我希望以下参考资料能对你有所帮助。

这是Android中SQLite数据库的教程:http://www.vogella.com/articles/AndroidSQLite/article.html

以下是我之前所做的连接到服务器上的PHP文件,并通过该PHP文件将数据提取或插入服务器上的数据库的代码截图。

new AsyncTask<String, Void, String>() {
@Override
protected String doInBackground(String... params) {
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost;
    httppost = new HttpPost(link_to_php_file); 
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    //Where you can pass parameter to the php file
    nameValuePairs.add(new BasicNameValuePair("name", value));
    nameValuePairs.add(new BasicNameValuePair("name2", value2));
    String str="";
    try {
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        str = Utils.convertStreamToString(entity.getContent());
    } catch (Exception e) {
        Log.e("log_tag", "Error in connection " + e.toString());
    }
    return str;
protected void onPostExecute(String result) {
    if (!TextUtils.isEmpty(result)) {
        JSONArray result_array = null;
        try {
            result_array = (JSONArray) new JSONArray(result);
        } catch (JSONException e1) {
            e1.printStackTrace();
        }                           
        try{
            for (int i = 0; i < count; i++) {
                JSONObject row = array.getJSONObject(i);
                //Do something with the result...                           
            }
        } catch (JSONException e){
            e.printStackTrace();
        }
    } 
};//End Of PostExecute
}.execute(); //End Of Async