title: connect android to mysql using jsp
body: <p>i am trying to connect with mysql using jsp below is the code of both the files android and jsp please have look on it its  neither working nor giving me any error what would be the problem?</p>
  
  <p>android code:</p>
  
  <pre><code> package com.example.prj;
  
  import java.io.BufferedReader;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.util.ArrayList;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicNameValuePair;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  Button submit;
  TextView tv;
  EditText et1,et2;
  String user,pass;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      submit=(Button)findViewById(R.id.button1);
      tv=(TextView)findViewById(R.id.textView1);
      et1=(EditText)findViewById(R.id.editText1);
      et2=(EditText)findViewById(R.id.editText2);
      //user=et1.getText().toString();
      //pass=et2.getText().toString();
  
      submit.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              try{
                  ArrayList&lt;BasicNameValuePair&gt; namevaluepair=new ArrayList&lt;BasicNameValuePair&gt;();
                  namevaluepair.add(new BasicNameValuePair("user", user=et1.getText().toString()));
                  namevaluepair.add(new BasicNameValuePair("pass", pass=et2.getText().toString()));
                  HttpClient client=new DefaultHttpClient();
                  HttpPost post=new HttpPost("http://10.0.2.2:8080/login.jsp");
                  post.setEntity(new UrlEncodedFormEntity(namevaluepair));
                  HttpResponse response=client.execute(post);
                  HttpEntity entity=response.getEntity();
                  InputStream in=entity.getContent();
                  try{
                      BufferedReader bf=new BufferedReader(new InputStreamReader(in));
                      StringBuilder sb=new StringBuilder();
                      String line=null;
                      while((line=bf.readLine())!=null){
  
                          sb.append(line);
  
                      }
                      String result=sb.toString();
                      if(result.equalsIgnoreCase("vinod")){
                          Intent i=new Intent(MainActivity.this,loggedin.class);
  
                          i.putExtra("key",user);
                          startActivity(i);
                      }else{
                          tv.setText("invalid");
                      }
  
  
                  }catch(Exception e){
                      e.printStackTrace();
                  }
              }catch(Exception e){
                  Log.e("log_tag", "Error in http"+e.toString());
              }
          }
      });
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.activity_main, menu);
      return true;
  }
  }
  </code></pre>
  
  <p>JSP code:</p>
  
  <pre><code>&lt;%@page import="java.io.*"%&gt;
  &lt;%@page import="java.sql.*"%&gt;
  &lt;%!
  String username;
  String password; 
  Statement stmt=null;
  ResultSet rs=null;
  Connection con=null;
  %&gt;
  &lt;%
  String driver="com.example.mysql.Driver";
  Class.forName(driver).newInstance();
  
  try{
   String url="jdbc:mysql://localhost/log";
    con = DriverManager.getConnection(url,"root","");
   stmt=con.createStatement();
  
  }catch(Exception e){
  e.printStackTrace(); 
  
  }
  if(!con.isClosed()){
  username=request.getParameter("user");
  password=request.getParameter("pass");
  rs=stmt.executeQuery("select * from login");
  while(rs.next()){
  if(rs.getString("user")==username &amp;&amp; rs.getString("pass")==password){
   out.println("vinod");
   System.out.println("vinod kakad");
  }else{
  
   out.println("vinod");
   System.out.println("vinod kakad else part");
  }
  }
    else{
    out.println("lost");
    System.out.println("vinod kakad else lost part");
    } 
  
  
    }
  
   %&gt;
  </code></pre>