As a good coding practice, try to minimize the use of scriptlets inside JSPs and definitely stay away from
JDBC stuff inside
Java Server Pages. All this code should be inside a
Servlet or better yet a Java Bean.
To your question,
try using JSTL to iterate over your collection, see the example below
Notice the use of varStatus. This would be your actual counter that will be incremented by one(default) on each iteration. If you need 4 records per row you would need to
check for the remainder of the counter by 4 (status.count % 4 == 0). If that's the case, end the row </tr> and start a new one <tr>. That will guarantee that you only
have 4 records per row and will give you a much cleaner code