无法使用Android在mysql中插入数据 [英] Cannot Insert data in mysql using Android

查看:42
本文介绍了无法使用Android在mysql中插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to insert registration data in mysql . I was using PHP file, to connect with MYSQL.. Reference: http://sampleprogramz.com/android/mysqldb.php#

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

With this , I can successfully save my data in database using PHP but now I want to use java instead of php...I couldn't save it in 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 ..

Now I want to work with java webservice...and for it , I should convert this ArrayList to Xmlstring ..

请帮助我,如何将nameValuePairs转换为XMLString...通过它,我可以使用StringEntity并在webservice中传递数据...提前

Please help me for this, How can I convert nameValuePairs to XMLString...Through it , I can take StringEntity and pass data in webservice...Thx in advance

推荐答案

你不能像调用 php 那样调用 java-webserviec.你必须使用soap对象来实现它我认为这个链接可能对你有帮助.java 网络服务

you can't call java-webserviec just like that you do with php. you have to implement it using soap object i think this link might be helpful to you. java webservice

这篇关于无法使用Android在mysql中插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆