• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Managing view of database data in jsp

 
Ranch Hand
Posts: 75
Eclipse IDE AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 19
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 75
Eclipse IDE AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 7135
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The knights of nee want a shrubbery. And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic