Using this code i attained a resultset object which i want to pass it to the jsp page for display.How to pass the object? Can anyone help me out? Thanx in advance. Visu N
[Edit - code tags added, broke up long lines] [ December 16, 2005: Message edited by: David O'Meara ]
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
Have a look at the HttpServletRequest.setAttribute method.
I wont recommend your standards !! I think it will be good if you seperate your application into different layers. You can have an action class, business layer, DAO layer and make use of VO objects to pass data between layers. Just a suggestion
To pass your resultset to jsp, make use of the HttpServletRequest object
in your servlet request.setAttribute("resultset",rs);
I disagree completely, do NOT pass the resiult set from the Servlet to the JSP. This is a dangerous practice since it can cause memory leaks since you will not be able to close the connection, and ResultSet objects are not serialisable so you will have problems in some containers.
You need to perform the query, load the database results into something else, then send these results to the JSP for display. This is where ORM layers such as Hibernate, Toplink etc come in so handy.
Also, please look at using PreparedStatements, they will also save you a lot of trouble in the future.
I concur, result sets are not serializable and therefore should never be passed over any transport level. You an use auto-generation tool or IDE (like Eclipse) to create a simple DTO object with getters/setters and send as that, or an array of them.
On top of that, given you can vary the fetch size of the result set, I'm not even sure it would work without throwing serious errors. [ December 16, 2005: Message edited by: Scott Selikoff ]
ResultSet object becomes invalid/closed after closing its statement.
The best practice is to release DB resources as soon as you are finished with those to avoid sticking with database, just for nothing.
Docs: A Statement object is automatically closed when it is garbage collected. When a Statement object is closed, its current ResultSet object, if one exists, is also closed.