title: From a drop down- display data corresponding to it from database into text boxes using JSP
body: <p>I m trying to select data from a drop down and retrieve &amp; display the values corresponding to it into textboxes.. the data to be displayed into the textboxes is taken from database(mysql database).. The scripting is done in JSP which is as follows:</p>
  
  <p>issue_from.jsp</p>
  
  <pre><code>function showDataIssue(){ 
  xmlHttp=GetXmlHttpObject()
  var id=document.getElementById("part_no").value;
  var url="issue_upd.jsp";// code for issue_upd.jsp is given down
  url=url+"?part_no="+id;
  xmlHttp.onreadystatechange=stateChanged 
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null);
  }
  </code></pre>
  
  <p>Here part_no is the key- whose values are in the drop-down and on selecting any part_no value, the corresponding values for part_desc, serial_no, mr_no rr_no and po_no are to be displayed in the text boxes. The fields part_no,part_desc, serial_no, mr_no and rr_no are in one table called mr_details. The fields part_no, po_no are in one table called po_details.</p>
  
  <p>issue_form.jsp</p>
  
  <pre><code>function stateChanged(){ 
  if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
  var showdata = xmlHttp.responseText; 
  var strar = showdata.split(":");
    if(strar.length&gt;1){
      var strname = strar[1];
      document.getElementById("mr_no").value= strar[1];
      document.getElementById("rr_no").value= strar[2];
      document.getElementById("serial_no").value= strar[3];
      document.getElementById("part_desc").value= strar[4];
      document.getElementById("po_no").value= strar[5];
       }
     } 
   }
  </code></pre>
  
  <p>In above code I m trying to get the values of the fields. The code for issue_upd.jsp is as follows:</p>
  
  <p>issue_upd.jsp</p>
  
  <pre><code>String pn = request.getParameter("part_no").toString();
  System.out.println(pn);
  String data ="";
  try{
         Class.forName("com.mysql.jdbc.Driver");
         Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/");
         Statement st=con.createStatement();
         ResultSet rs=st.executeQuery("select mr_no,rr_no,serial_no,part_desc from  where         part_no='"+pn+"'");
         ResultSet rs1=st.executeQuery("select po_no from po_details where part_no='"+pn+"'");
  while(rs.next())
  {
   data = ":" + rs.getString("mr_no") + ": " + rs.getString("rr_no") + ": " +         rs.getString("serial_no")+ ": " + rs.getInt("part_desc")+ ": " + rs1.getInt("po_no");
  }
  out.println(data);
  System.out.println(data);
  }catch(Exception e) {
  System.out.println(e);
  }
  </code></pre>
  
  <p>For the drop down I have written code in Java which is as follows:</p>
  
  <p>issue_form.java</p>
  
  <pre><code>public class issue_details {
  public ResultSet get_part_no() {
  ResultSet rs;       
  try{
         Class.forName("com.mysql.jdbc.Driver");
         Connection con =DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb");
         Statement st=con.createStatement();
        rs=st.executeQuery("select part_no from mr_details");
  
  
  }
  catch(Exception e) {
  System.out.println(e);
  rs=null;
  }
  return rs;
  }
  </code></pre>
  
  <p>And the JSP code for drop down is as follows:</p>
  
  <p>issue_form.jsp</p>
  
  <pre><code>&lt;select id="part_no" name="part_no" onchange="showDataIssue();"/&gt;
  
  &lt;%  issue_details p=new issue_details();
  ResultSet res = p.get_part_no();
  while(res.next())
  {
  
   %&gt;
   &lt;option value="&lt;%=res.getString("part_no") %&gt;"&gt;&lt;%=res.getString("part_no")%&gt;
   &lt;%=res.getString("part_no") %&gt;&lt;/option&gt;
  
   &lt;%
   } %&gt;
  </code></pre>
  
  <p>The problem is that I am not able to retrieve the values from the database. Neither the drop values are displayed . Anyone please help me find the errors in the code. It would be of great help for me. Thanks in advance.</p>