2

I am trying to Select data from a Table Clients, and display it using a servlet in the form of an HTML table. The problem I face is in the display of the table, the cells in each row do not match with the cells from the next row in width, how can it fix this ?

Problem solved

                      try {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            Connection cnx=DriverManager.getConnection("jdbc:derby://localhost:1527/ndb","me","123");
            Statement st=cnx.createStatement();
            ResultSet rs=st.executeQuery("Select * from Clients");

            out.println("<HTML>");
            // Start on the body
            out.println("<BODY>");
            out.println("<CENTER>");
            out.println("<table BORDER=1 CELLPADDING=0 CELLSPACING=0 WIDTH=50% >");
            while (rs.next()){



            out.println("<tr>");
            out.print("<td>"+rs.getString("CIN")+ "</td>");
            out.print("<td>"+rs.getString("NOM")+ "</td>");
            out.print("<td>"+rs.getString("PRENOM")+ "</td>");
            out.print("<td>"+rs.getString("TEL")+ "</td>");
            out.print("<td>"+rs.getString("EMAIL")+ "</td>");
            out.print("<td>"+rs.getString("SEX")+ "</td>");
            out.println("</tr>");


           }
          } catch(Exception ex){
           } 

            out.println("</table>");
             out.println("</CENTER>");
             out.println("</BODY></HTML>");
       }
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2161721
  • 164
  • 1
  • 2
  • 11
  • All the attribute values such as `BORDER=1 CELLPADDING=0 CELLSPACING=0 WIDTH=50%` must be enclosed in single or double quotes. – Braj Mar 22 '14 at 20:04
  • 1
    You have created multiple HTML tables based on resultant rows. Move code till `out.println("");` outside the `while` loop and do same thing from `out.println("
    ");`. It means only `` and `` must be created in `while` loop.
    – Braj Mar 22 '14 at 20:08
  • thanks man, I feel so stupid right now. – user2161721 Mar 22 '14 at 20:15
  • 2
    You are better of using a `JSP`s instead of a `Servlet`s, this will allow you to type HTML outside of `out.print("...");` statements and make the code more clear and maintainable. – Benjamin Albert Mar 22 '14 at 20:19
  • Still `HTML` and `` tags are placed inside `while` loop. – Braj Mar 22 '14 at 20:25
  • I fixed the tags, but what do u mean "using quotes for attribute values" ? – user2161721 Mar 22 '14 at 20:43

0 Answers0