NealCaffrey 0 Newbie Poster

I m trying to select data from a drop down and retrieve & 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:

issue_from.jsp

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);
    }

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.

issue_form.jsp

function stateChanged(){ 
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    var showdata = xmlHttp.responseText; 
    var strar = showdata.split(":");
      if(strar.length>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];
         }
       } 
     }

In above code I m trying to get the values of the fields. The code for issue_upd.jsp is as follows:

issue_upd.jsp

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);
    }

For the drop down I have written code in Java which is as follows:

issue_form.java

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;
    }

And the JSP code for drop down is as follows:

issue_form.jsp

<select id="part_no" name="part_no" onchange="showDataIssue();"/>
           
    <%  issue_details p=new issue_details();
    ResultSet res = p.get_part_no();
    while(res.next())
    {
        
     %>
     <option value="<%=res.getString("part_no") %>"><%=res.getString("part_no")%>
     <%=res.getString("part_no") %></option>

     <%
     } %>

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.