繁体   English   中英

无法使用Android在mysql中插入数据

[英]Cannot Insert data in mysql using Android

我试图在mysql中插入注册数据。 我使用的是PHP文件,用于与MYSQL连接。参考: http : //sampleprogramz.com/android/mysqldb.php#

有了这个, 我可以使用PHP成功地将数据保存在数据库中,但是现在我想使用Java而不是php ...我无法将其保存在db中

我的代码:

 ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

    nameValuePairs.add(new BasicNameValuePair("registerId",""));
    nameValuePairs.add(new BasicNameValuePair("registerName",reg_name));
    nameValuePairs.add(new BasicNameValuePair("regContactNo",contactno));
    nameValuePairs.add(new BasicNameValuePair("regEmailAddr",emailaddr));
    nameValuePairs.add(new BasicNameValuePair("registerDesignation",designation));
    nameValuePairs.add(new BasicNameValuePair("regCmpnyName",company_name));
    nameValuePairs.add(new BasicNameValuePair("evtCd",eventCode));
    StrictMode.setThreadPolicy(policy);

    //http post
    try{
        HttpClient httpclient = new DefaultHttpClient();

        HttpPost httppost = new HttpPost("http://url/useracc/register");

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
        Log.e("Response:" , response.toString());
        Log.e("is",""+is);

        Log.e("log_tag", "connection success ");
        Toast.makeText(getApplicationContext(), "pass", Toast.LENGTH_SHORT).show();

    }

    catch(Exception e)
    {
        Log.e("log_tag", "Error in http connection "+e.toString());
        Toast.makeText(getApplicationContext(), "Connection fail", Toast.LENGTH_SHORT).show();

    }
    //convert response to string
    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");
            Intent i = new Intent(getBaseContext(),DatabaseActivity.class);
            startActivity(i);*/
        }
        is.close();

        result=sb.toString();
    }
    catch(Exception e)
    {
        Log.e("log_tag", "Error converting result "+e.toString());
    }

    try{

        JSONObject json_data = new JSONObject(result);

        CharSequence w= (CharSequence) json_data.get("re");

        Toast.makeText(getApplicationContext(), w, Toast.LENGTH_SHORT).show();


    }
    catch(JSONException e)
    {
        Log.e("log_tag", "Error parsing data "+e.toString());
       // Toast.makeText(getApplicationContext(), "JsonArray fail", Toast.LENGTH_SHORT).show();
    }

现在,我想使用java webservice ...,为此,我应该将此ArrayList转换为Xmlstring ..

为此,请帮帮我,如何将nameValuePairs转换为XMLString ...通过它,我可以获取StringEntity并在webservice中传递数据... Thx

您不能像使用php一样调用java-webserviec。 您必须使用soap对象来实现它,我认为此链接可能对您有所帮助。 Java Web服务

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM