Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Display certain data from database by passing the parameters.  RSS feed

 
Ummu Hanisah
Greenhorn
Posts: 10
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I would like to display certain data from database by passing the parameters from a jsp page to a servlet. Instead of displaying the records, it keeps displaying 27 lines of the same parameter that I pass from jsp page on the console. The 27 lines of printed parameters seems to be the quantity of rows of the selected data that should be displayed. This is the first time I'm using the standard coding in displaying certain data from database. I cannot trace which line that I should make the changes.


Here is my jsp code, PatronForm.jsp


This is my servlet, PatronReservationProcess.java


DisplayPatronReservation.jsp
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a class that contains Stime,Etime,Reservedate,Roomtype,roomname,pax and reservationid (if you don't have it already). Lets say you call this class Reservation. Then instead of doing

List dataList = new ArrayList();
you do
List<Reservation> dataList = new ArrayList<Reservation>();
and you create ad add reservation objects to the list as you move through the result set.
In the JSP you must call itr.next() only once to get the next record and then display it's properties.

Other things you should look at are
1.) Use a PreparedStatement for building your queries to prevent sql injection attacks.
2.) Use jstl tags to do your display logic instead of mixing java with html
3.) Use consistent conventional naming standards for you variable names. Some of your variable names start with upper case characters while some start with lower case. They should all be camel case starting with lower case characters.
4.) Consider moving the database logic out of the servlet into a separate normal Java class that you can reuse and test without needing to start a servlet container




 
Ummu Hanisah
Greenhorn
Posts: 10
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response. I'm aware with some of your suggestion. My project's dateline is around the corner. I will try my best to implement all of them. Thanks again.
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can leave out 2.) until right at the end if you have time. 4.) Will speed up the rest of your development because it allows you to test your database code quickly without involving the server. The rest are easy and quick to do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!