Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Managing view of database data in jsp

 
Saumyaraj Zala
Ranch Hand
Posts: 65
AngularJS Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using jsp and want to view a database(access) table in jsp page.The problem is the number of rows that would be displayed in jsp page would be dynamically made(by counting number of rows in database table).So how can i achieve that?Right now i am trying something like this.

Where my table has three columns ID,code and description.
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4680
329
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vivek K Jain
Greenhorn
Posts: 19
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try developing the habit of reading FAQs..the exact answer for your query is there.

JSPFAQ
 
Saumyaraj Zala
Ranch Hand
Posts: 65
AngularJS Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Modern JSPs -- that is any written in the past 12 years -- should not have Java code in them. Use modern techniques such as the JSTL and EL instead. The DB code should be in Java classes, not the JSP.
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4680
329
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic