Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display resultset from servlet on jsp

 
M Ryder
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to determine the best way to get a resultset from a servlet to display as a report on a jsp page. Any suggestions?
Thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65114
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strictly speaking, you should never have a resultset in a servlet. DB access should happen at a lower layer, with non-DB constructs passed up to the UI layer. If you're doing your DB access in a servlet, you're not following best practices (MVC) for web app design.

That said, regardless of where you do the DB access, you should copy the data from the resultset into another construct (Lists, arrays, whatever makes the most sense for the nature of the data) and close the rsultset and statement as soon as possible.

For reporting, are you rolling your own, or using a prefab reporting package? That might dictate what format you transform the resultset data into. For simply showing a grid of data on a JSP, copying the data into a simple Object[][] can work just fine.
 
M Ryder
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear. I will review the mvc.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65114
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would be best long-term, but did you get the thrust of my post regarding not leaving resultsets open for long periods by copying the data?
 
M Ryder
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I got it.. makes sense
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic