I am developing my college internship project technology using j2ee with HTML. I am able to retrieve data from the database and also able to create the table which is displaying the result. The problem is that the table is showing the result first and then on the second line it is showing the headers name. Please help me out in this and also let me know, how to create a html page with servlet code which can edit the data in the database as per required by the user. A very big thanks in advance.
Here is the code.
PrintWriter out = response.getWriter();
String sql;
String input = request.getParameter("list");
String txtField = request.getParameter("txtField");
try {
sql = String.format("select * from adddriver where (%s) = '%s'",input, txtField);
ResultSet rs = DBConnection.executeQuery(sql);
ResultSetMetaData metadata = rs.getMetaData();
int colCount = metadata.getColumnCount();
out.println("<table border=1>" + "<tr>");
for(int i=1;i<=colCount;i++)
{
out.println("<th>"+metadata.getColumnName(i)+"</th>");
}
out.println("</tr>");
/* Printing result */
while(rs.next())
{
String[] rowData = new String[colCount];
for(int i =0; i<colCount; i++){
rowData[i] = rs.getString(i+1);
out.println(rowData[i]);
//out.println("<tr><td>"+rs.getInt(1)+"</td><td>"+rs.getString(2)+" </td><td>"+rs.getString(3)+"</td><td>"+rs.getString(4)+"</td><td>"+rs.getString(5)+" </td><td>"+rs.getString(6)+" </td></tr>");
}
}
}
catch(SQLException sqe){
sqe.getStackTrace();
}
}