Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6209685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:01:46+00:00 2026-05-24T06:01:46+00:00

I connect a database on my server from the Android application and I want

  • 0

I connect a database on my server from the Android application and I want to use the info the server send back to me.
Here is the response I get from the server :

[{"id":"1","userid":"1159448580","address":"Kishinev 3"}]

Here is my function that is realizing the connection to the server and trying to parse the response :

String checkForUserIdGetBookmarks (String returnString) {
        InputStream is = null;
        String result = "";
        //the userId data to send
        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("userId", userId));

        //http post
        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(PHP_URL);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
        } catch(Exception e){
            Log.e("log_tag", "Error in http connection "+e.toString());
        }

        //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");
            }
            is.close();
            result = sb.toString();
        } catch(Exception e) {
            Log.e("log_tag", "Error converting result "+e.toString());
        }

        //parse json data
        try {
            JSONArray jArray = new JSONArray(result);
            for (int i=0; i<jArray.length(); i++) {
                JSONObject json_data = jArray.getJSONObject(i);
                Log.i("log_tag","id: "+json_data.getInt("id")+
                        ", userid: "+json_data.getString("userid")+
                        ", address: "+json_data.getInt("address")
                        );
                //Get an output to the screen
                returnString += "\n\t" + jArray.getJSONObject(i);
            }
        } catch(JSONException e) {
            Log.e("log_tag", "Error parsing data "+e.toString());
        }

        return returnString;
    }

But when I try to show the already converted string it shows an empty string.

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
            String returnString = "";
        checkForUserIdGetBookmarks(returnString);
        Toast useridToast = Toast.makeText(getApplicationContext(), returnString, Toast.LENGTH_LONG);
        useridToast.show();

Where would you suggest is my mistake and do you know other way of getting the response from the server into a string which I can use afterwards?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:01:47+00:00Added an answer on May 24, 2026 at 6:01 am

    Use:

    String returnString = checkForUserIdGetBookmarks(); // and declare returnString inside the method
    

    Instead of:

    String returnString = "";
    checkForUserIdGetBookmarks(returnString);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can connect to my SQL Server database via sqlcmd from a DOS command
So our web server apps need to connect to the database, and some other
How do I connect to an SQL Server remotely and administer my database objects?
I'm writing a database application that connects to SQL server. I'd like to implement
How do I connect to a remote Oracle database instance from PHP? I need
I have created a simple JSF application, now must to connect to SQL Server
Folks, I connect to a large number of SQL Server 2005 databases through SQL
How do I connect to the database(MYSQL) in connection bean using JSF to retrieve
While trying to connect to a database that's set to read only, the connection
Is it possible to configure nHibernate to connect to Paradox database ( *.db files)?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.