为什么我的MySQL日期字段显示为“0000.00.00”?

时间:2014-02-04 00:23:28

标签: php android mysql

我创建了一个MySQL表“Absence”,其中包含列(id,StartDate,EndDate,Reason)。我用PHP在Android和MySQL之间建立了联系。一切都很顺利,但在查看日期时仍显示“0000.00.00”。当我使用phpMyAdmin访问我的数据库时,我看到同样的问题。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

public class Ajouter扩展了Activity {

private ProgressDialog pDialog;

JSONParser jsonParser = new JSONParser();
EditText inputMatricule;
EditText inputDateDebut;
EditText inputDateFin;
EditText inputRaison;

// url to create new product
private static String url_Ajouter_Absence = "http://10.0.2.2/android_connect/AjouterAbsence.php";

// JSON Node names
private static final String TAG_SUCCESS = "success";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ajouter);

    // Edit Text
    inputMatricule = (EditText) findViewById(R.id.InputMatricule);
    inputDateDebut = (EditText) findViewById(R.id.InputDateDebut);
    inputDateFin = (EditText) findViewById(R.id.InputDateFin);
    inputRaison = (EditText) findViewById(R.id.InputRaison);

    // Create button
    Button btnAjouterAbsence = (Button) findViewById(R.id.btnAjouterAbsence);

    // button click event
    btnAjouterAbsence.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            // creating new product in background thread
            new CreateNewProduct().execute();
        }
    });
}

/**
 * Background Async Task to Create new product
 * */
class CreateNewProduct extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Ajouter.this);
        pDialog.setMessage("Creating Product..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    /**
     * Creating product
     * */
    protected String doInBackground(String... args) {
        String Matricule = inputMatricule.getText().toString();
        String DateDebut = inputDateDebut.getText().toString();
        String DateFin = inputDateFin.getText().toString();
        String Raison = inputRaison.getText().toString();

        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("Matricule", Matricule));
        params.add(new BasicNameValuePair("DateDebut", DateDebut));
        params.add(new BasicNameValuePair("DateFin", DateFin));
        params.add(new BasicNameValuePair("Raison", Raison));

        // getting JSON Object
        // Note that create product url accepts POST method
        JSONObject json = jsonParser.makeHttpRequest(url_Ajouter_Absence,
                "POST", params);

        // check log cat from response
        Log.d("Create Response", json.toString());

        // check for success tag
        try {
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // successfully created product
                Intent i = new Intent(getApplicationContext(), Consulter.class);
                startActivity(i);

                // closing this screen
                finish();
            } else {
                // failed to create product
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog once done
        pDialog.dismiss();
    }

}

}