Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

why can't I display retrieved data from a mysql database on a webpage properly?  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How I want my code to work:
User types in a promo id, and data is retrieved from 'promotion' table in mysql according to what the user typed. For example, if user typed 'P01' for promo id, this is how it should look like (this is from a direct mysql query by the way):



The problem:
Data isn't displaying. (Only table headings are displayed)


There are no visible errors when I view my code in Eclipse.

moreinfo.jsp (takes in parameter of promo id; forwards it to PromotionDisplay servlet)



PromotionDisplayServlet



PromotionDisplay.java (object)



PromotionDB.java (takes in object PromotionDisplay)    



displayPromotion.jsp (display results in a tabular format)

 
Saloon Keeper
Posts: 5124
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In PromotionDB, does the loop add any elements to the ArrayList? Add some logging to find out for sure.
 
Marshal
Posts: 67192
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be putting any Java code into the JSP. Move the DB fetch code into normal classes which you can test to be sure the data is being fetch correctly.

Then in a servlet, call the classes to fetch the data and send it to the JSP for display.

Please see this article for a discussion of why Java web apps should be constructed that way.
 
Ranch Hand
Posts: 202
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debugging or logging saves ton of time as this situation.
 
I'm THIS CLOSE to ruling the world! Right after reading this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!