数据未保存到数据库

时间:2016-05-11 20:02:55

标签: android mongodb

在我的android应用程序中,我试图在MongoDB数据库中保存一些数据。我使用此代码(如下所示)。此代码显示Toast data is saved,但数据不存在于我的数据库中。我没有任何例外。亲切地说出可能是什么问题?

代码:

@Override
protected Boolean doInBackground(String... reminder) {
    try {
        URL requestUrl = new URL("MongoDB address");
        HttpURLConnection connection = (HttpURLConnection) requestUrl.openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json");
        connection.connect();
        OutputStream save = connection.getOutputStream();
        save.write(reminder[0].getBytes());
        save.close();
        connection.disconnect();

        new Handler(context.getMainLooper()).post(new Runnable() {
            public void run() {
                Toast.makeText(context, "data is saved", Toast.LENGTH_LONG).show();
            }
        });
    }
    catch(Exception exception) {
        Log.e("ERROR", "DB Saving", exception);
    }
    return true;
}

0 个答案:

没有答案