title: how to Retrieve data from database and display it in a jsp text fields using jdbc connection
body: <p>I am retrieving data from database and displaying it in table in a <code>JSP</code> but I do not have any idea about how to display it on text fields.</p>
  
  <p>e.g. </p>
  
  <ol>
  <li>when I search a index number.</li>
  <li>the the result (name , address, age) must come to the textfeilds which are in my <code>JSP</code></li>
  </ol>
  
  <p>My code:</p>
  
  <pre><code>public class S2 extends HttpServlet {
  
  
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      Connection conn = null;
      String url = "jdbc:mysql://localhost:3306/";
      String dbName = "shoppingCart";
      String driver = "com.mysql.jdbc.Driver";
      String userName = "root";
      String password = "";
  
      Statement st;
      try {
          Class.forName(driver).newInstance();
          conn = DriverManager.getConnection(url + dbName, userName, password);
          System.out.println("Connected!");
          String pid = request.getParameter("pid");
  
          ArrayList al = null;
          ArrayList pid_list = new ArrayList();
          String query = "select * from user where uid='" + pid + "' ";
  
          System.out.println("query " + query);
          st = conn.createStatement();
          ResultSet rs = st.executeQuery(query);
  
          while (rs.next()) {
  
              al = new ArrayList();
  
              out.println(rs.getString(1));
              out.println(rs.getString(2));
              out.println(rs.getString(3));
              out.println(rs.getString(4));
              out.println(rs.getString(5));
  
  
              al.add(rs.getString(1));
              al.add(rs.getString(2));
              al.add(rs.getString(3));
              al.add(rs.getString(4));
              al.add(rs.getString(5));
  
  
              System.out.println("al :: " + al);
              pid_list.add(al);
          }
  
  
          request.setAttribute("piList", pid_list);
          RequestDispatcher view = request.getRequestDispatcher("/searchview.jsp");
          view.forward(request, response);
          conn.close();
          System.out.println("Disconnected!");
      } catch (Exception e) {
          e.printStackTrace();
      }
  </code></pre>