title: Android: Facing issue-'BasicNetwork.performRequest: Unexpected response code 500'
body: <p>I am trying to send data from an an Android app to a Servlet.
  My Android Application is working properly.</p>
  
  <p>The issue is only with the request sent to the Servlet. It gives error BasicNetwork.performRequest: Unexpected response code 500</p>
  
  <p>Note: I am using Android Volley library to send my request to the Servlet.</p>
  
  <p>Below I have mentioned:
   1. My Android app code
   2. My Servlet Code
   3. LogCat</p>
  
  <p>My Android App: MainActivity.java File</p>
  
  <pre><code>            package com.example.hawk;
  
              import java.util.HashMap;
              import java.util.Map;
  
              import com.android.volley.AuthFailureError;
              import com.android.volley.Request;
              import com.android.volley.RequestQueue;
              import com.android.volley.Response;
              import com.android.volley.toolbox.StringRequest;
              import com.android.volley.toolbox.Volley;
  
              import android.support.v7.app.ActionBarActivity;
              import android.app.Activity;
              import android.os.Bundle;
              import android.view.Menu;
              import android.view.MenuItem;
              import android.view.View;
              import android.view.View.OnClickListener;
              import android.widget.Button;
              import android.widget.EditText;
  
              public class MainActivity extends Activity implements View.OnClickListener {
  
              EditText var_sp = null;
              EditText var_ect = null;
              EditText var_er = null;
              EditText var_iat = null;
              EditText var_atp = null;
              Button submit;
              RequestQueue rq = null;
  
              @Override
              protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              v1 = (EditText) findViewById(R.id.sp);
              v2 = (EditText) findViewById(R.id.ect);
              v3 = (EditText) findViewById(R.id.er);
              v4 = (EditText) findViewById(R.id.iat);
              v5 = (EditText) findViewById(R.id.atp);
              submit = (Button) findViewById(R.id.submit);        
              rq=Volley.newRequestQueue(this);
              submit.setOnClickListener(this);
              }
              @Override
              public boolean onCreateOptionsMenu(Menu menu) {
              // Inflate the menu; this adds items to the action bar if it is present.
              getMenuInflater().inflate(R.menu.main, menu);
              return true;
              }
  
              @Override
              public boolean onOptionsItemSelected(MenuItem item) {
              // Handle action bar item clicks here. The action bar will
              // automatically handle clicks on the Home/Up button, so long
              // as you specify a parent activity in AndroidManifest.xml.
              int id = item.getItemId();
              if (id == R.id.action_settings) {
              return true;
              }
              return super.onOptionsItemSelected(item);
              }
  
              @Override
              public void onClick(View v) {
              switch (v.getId()) {
              case R.id.submit:
  
              new Thread(new Runnable() {
              public void run() {
              try{
              StringRequest postReq = new StringRequest(Request.Method.POST, "http://192.168.0.103:8080/ServletABC",new Response.Listener&lt;String&gt;() {
              protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
                  Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
                  params.put("var1",v1.getText().toString());
                  params.put("var2",v2.getText().toString());
                  params.put("var3",v3.getText().toString());
                  params.put("var4",v4.getText().toString());
                  params.put("var5",v5.getText().toString());
                  return params;
              }
  
              @Override
              public void onResponse(String response) {
                  // TODO Auto-generated method stub
  
              }
  
              }, null);
  
              rq.add(postReq);
              }catch(Exception e)
              {
              e.printStackTrace();
              }
  
              }
              }).start();
  
              break;
  
  
              }
              }
              }
  </code></pre>
  
  <p>My Servlet:</p>
  
  <pre><code>            import java.io.*;
              import java.util.*;
              import javax.servlet.*;
              import javax.servlet.http.*;
              import java.sql.*;
  
              public class OBD_Feeder extends HttpServlet{
                   // JDBC driver name and database URL 
                   public static final String JDBC_DRIVER="com.mysql.jdbc.Driver";
                   public static final String DB_URL="jdbc:mysql://localhost/Test";
                   // Database credentials 
                   public static final String USER ="xxxx";
                   public static final String PASS ="xxxx";
                   Connection conn;
                   Statement stmt;
  
                   public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
                  {       
                      response.setContentType("text/html");
                      PrintWriter out = response.getWriter();
                      double v1=Double.parseDouble(request.getParameter("var1")); 
                      double v2=Double.parseDouble(request.getParameter("var2"));
                      double v3=Double.parseDouble(request.getParameter("var3"));
                      double v4=Double.parseDouble(request.getParameter("var4"));
  double v5=Double.parseDouble(request.getParameter("var5"));
                      Calendar calendar = Calendar.getInstance();
                  java.sql.Timestamp today_ts = new java.sql.Timestamp(calendar.getTime().getTime());
  
              //System.out.println("TimeStamp: "+today_ts);
  
                  try{     
                   // Register JDBC driver 
                       Class.forName("com.mysql.jdbc.Driver");
                       // Open a connection 
                       conn =DriverManager.getConnection(DB_URL,USER,PASS);
  
                       // Execute SQL query 
                       stmt = conn.createStatement();
                       PreparedStatement pst =(PreparedStatement) conn.prepareStatement("insert into obd_test1(speed,coolant_temp,engine_rpm,in_air_temp,throttle_position, time_stamp) values(?,?,?,?,?,?)");
  
                    pst.setDouble(1,v1);  
                    pst.setDouble(2,v2);        
                    pst.setDouble(3,v3);
                    pst.setDouble(4,v4);
                    pst.setDouble(5,v5);
                    pst.setTimestamp(6,today_ts);
                    System.out.println("DB Query: "+pst.toString());
                    //Query execution
                    int i = pst.executeUpdate();
                    //conn.commit(); 
                    String msg=" ";
                    if(i!=0){msg="Record has been inserted";}  
                    else{msg="failed to insert the data";}
                    System.out.println("DB Transaction Status: "+msg);
                  String docType ="&lt;!doctype html public \"-//w3c//dtd html 4.0 "+"transitional//en\"&gt;\n";
                  out.println(docType +
                  "&lt;html&gt;\n"+
                  "&lt;head&gt;&lt;title&gt;OBD Feeder&lt;/title&gt;&lt;/head&gt;\n"+
                  "&lt;body bgcolor=\"#f0f0f0\"&gt;\n"+
                  "&lt;h1 align=\"center\"&gt;DATA Received:&lt;/h1&gt;\n"+
                  "&lt;ul&gt;\n"+msg+"&lt;/ul&gt;\n"+
                  "&lt;/body&gt;&lt;/html&gt;");
  
                    pst.close();
                  stmt.close();
                  conn.close();
                   }catch(SQLException se){ se.printStackTrace();}//Handle errors for JDBC se.printStackTrace();
                   catch(Exception e){ e.printStackTrace();}//Handle errors for Class.forName e.printStackTrace();
                   finally
                   { //finally block used to close resources 
                      try{ 
                          if(stmt!=null) 
                          stmt.close();
                      }catch(SQLException se2){ se2.printStackTrace();}// nothing we can do 
                      try{ 
                              if(conn!=null) 
                              conn.close();
                          }catch(SQLException se){ se.printStackTrace();
                          }//end finally try 
                       }      
                  }   
              }
  </code></pre>
  
  <p>My LogCat:</p>
  
  <pre><code>            08-15 10:42:55.128: I/HAWK(29403): POST Request: [ ] http://192.168.0.102:8080/OBD_Feeder 0x85adf656 NORMAL 3
              08-15 10:42:55.408: E/Volley(29403): [1056] BasicNetwork.performRequest: Unexpected response code 500 for http://192.168.0.102:8080/ServletABC
              08-15 10:42:55.408: D/HAWK(29403): Error: null
              08-15 10:44:56.648: W/IInputConnectionWrapper(29403): getTextBeforeCursor on inactive InputConnection
  </code></pre>