How to Display a Table Data using Servlets in HTML Form -JDBC

Discussions

Web tier: servlets, JSP, Web frameworks: How to Display a Table Data using Servlets in HTML Form -JDBC

  1. I Want to diaplay the contents of a table using JDBC,and want to display the reults in a servlet which is writing in an HTML Format.The Format has Four Buttons marked FIRST,PREV,NEXT,LAST so that they display four fields in the relevant textfields and I don't want to use AWT.It has to be in HTML Page.Can I write JavAScript for these buttons inside the Servlet.
  2. Hi,
    res is the object of HttpServletResponse
    Use PrintWriter pw = res.getWriter() to write the html page in servlet. try the following:

    Connection con = DriverManager.getConnection();
    Statement st = con.createStatement();
    String str = SQL query;
    ResultSet rs = st.executeQuery(str);
    pw.println("<html><table><tr>");
    while(rs.next())
    {
    pw.println("<td>"+rs.getString(field name)+"</td>");
    }
    pw.println("</tr></table></html>");