File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes displaying multiple columns in html table in jsp from mysql database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "displaying multiple columns in html table in jsp from mysql database" Watch "displaying multiple columns in html table in jsp from mysql database" New topic
Author

displaying multiple columns in html table in jsp from mysql database

Kenneth Owino
Greenhorn

Joined: Aug 09, 2010
Posts: 23
Hi! I'm finding trouble on how to display more than one column from mysql database table into an html table in jsp. So far I can display rows of only one column using the code below. Someone help me on how I can display say table rows from more than one column.

This is the JSP:



And the DAO that accesses the database:



And the DTO:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

Please post an SSCCE of your issue. You've posted way too much unnecessary code to wade through.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kenneth Owino
Greenhorn

Joined: Aug 09, 2010
Posts: 23
Ok. Thank you for the reply. Actually, I have a database table with 2 columns "firstname" and "lastname". All I need is to retrieve all the rows in these columns and display them in an html table in my JSP. I read that using JSTL is a good practice and I tried using forEach. In doing this I created 2 DTOs 1 that gets firstname and 1 that gets lastname and two respective DAOs to access the database and returns arrayLists for each of the columns. Now the problem is I'm only able to use one DAO and one DTO that displays the firstname column from the table. How can I make all the columns be displayed? This part of the JSP only displays a table with one column:


How do I add the column under header
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Two DTOs? One for firstname, one for lastname?

That doesn't make sense to me. If you're going to get one, you're probably going to want the other.
Why make two trips?

What I would expect is that your DAO layer would return a list of Beans, with all the attributes that you need on them.
So rather than a firstnameDTO, and lastnameDTO, I would expect a StudentDTO which has firstname and lastname attributes (and email, and student id etc etc)

Suggestions on coding style/convention
- Classes should start with a capital letter. fnmDto should be FnmDto.
- fnmDto is a horrible name anyway. I presume it is "first name data transfer object"? Just for readability use "firstName" rather than "fnm"


You then iterate over that list of StudentDTOs, and display the attributes as you wish.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: displaying multiple columns in html table in jsp from mysql database
 
Similar Threads
What American Accent Do You Have?
Page displaying in IE6 and older versions but not in Higher versions, chrome and firefox also.
problem in running a servlet
white-space nowrap and DOCTYPE
fixed header, problem with alignment, must support all browsers