Where my table has three columns ID,code and description.
Devaka Cooray wrote:What does 'r' refer here? Note that you are following a really bad architecture if 'r' is a JDBC ResultSet reference. JSP are only for viewing purposes and the codes accessing your database should be separated from the view. Answering you question, what you should do here is fetching out the database results into an array or a collection and iterate over it in the JSP page using <c:forEach> JSTL tag.
You are right.I have used 'r' to refer ResultSet.
So according to you should i separate my code in from jsp in the form of servlet?
Saumyaraj Zala wrote:So according to you should i separate my code in from jsp in the form of servlet?
Not everything should be in Servlets. Accessing your database directly from a Servlet is again not a good practice - you will soon be banging your head over reusability constraints when you do that. Better way is using separate set of reusable classes where your database access logic resides. Use servlets only for controlling and delegating requests between views and models. Read this article to know more about the whole shebang behind the scene of MVC pattern in a Servlet environment.