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

  • SEARCH
  • Home
  • 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 8776561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:05:19+00:00 2026-06-13T19:05:19+00:00

I was reading a tutorial about how to connect android to mysql database over

  • 0

I was reading a tutorial about how to connect android to mysql database over the internet using a php interface.
I made everything as it said to.

the php code is this:

  $q=mysql_query("SELECT * FROM people WHERE birthyear>'".$_REQUEST['year']."'");
  while($e=mysql_fetch_assoc($q))
  $output[]=$e;

  print(json_encode($output));

  mysql_close();
?>

and the java code is this:

String result = "";
//the year data to send
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("year","1980"));

//http post
try{
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://example.com/getAllPeopleBornAfter.php");
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    InputStream 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")+
                    ", name: "+json_data.getString("name")+
                    ", sex: "+json_data.getInt("sex")+
                    ", birthyear: "+json_data.getInt("birthyear")
            );
    }
}
}catch(JSONException e){
    Log.e("log_tag", "Error parsing data "+e.toString());
}

Now the problem is it gives me an error that the variable ‘is’ doesn’t exist!
what should I do?

The tutorial is from website helloandroid.com : http://www.helloandroid.com/tutorials/connecting-mysql-database

  • 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-06-13T19:05:20+00:00Added an answer on June 13, 2026 at 7:05 pm
    try{
        InputStream is = entity.getContent();
        ...
        ...
    } //'is' goes out of scope here! 
    

    The scope is limited to the first try-catch block, and hence, is is unavailable in the second.

    Do:

    InputStream is = entity.getContent(); // 'is' now accessible in both try-catch
    HttpEntity entity = response.getEntity(); // 'entity' is now accessible in both try-catch
    try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://example.com/getAllPeopleBornAfter.php");
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        ...
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading a tutorial about creating a shoutbox with jquery, php and ajax. In
When I was reading this tutorial I noticed the following performance tip about using
I was reading a tutorial http://www.raywenderlich.com/1914/how-to-save-your-app-data-with-nscoding-and-nsfilemanager about using NSCoding so that I can save
I was reading some tutorial about openGL in qt. One of the mouse event
I'm reading the tutorial about configuring JSON for RESTful web services: https://blogs.oracle.com/enterprisetechtips/entry/configuring_json_for_restful_web JAXB defines
I was reading sbt tutorial , and I wanted to understand the part about
I'm reading a tutorial about Firefox extensions and one of the important files is
When reading the tutorial of Properties Tutorial from MSDN. I'm consused about the example.
I am just a beginner at windows programming and was reading a tutorial about
I am reading Nehe OpenGL tutorial and there is a tutorial about Display Lists.

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.