aspose file tools*
The moose likes JSP and the fly likes Managing view of database data in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Managing view of database data in jsp" Watch "Managing view of database data in jsp" New topic
Author

Managing view of database data in jsp

Saumyaraj Zala
Ranch Hand

Joined: Aug 06, 2012
Posts: 56

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.


Why do we fall? So that we can learn to pick ourselves up.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3098
    
  40

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.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Vivek K Jain
Greenhorn

Joined: Mar 17, 2013
Posts: 19

Try developing the habit of reading FAQs..the exact answer for your query is there.

JSPFAQ
Saumyaraj Zala
Ranch Hand

Joined: Aug 06, 2012
Posts: 56

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

Joined: Jan 10, 2002
Posts: 61206
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3098
    
  40

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Managing view of database data in jsp