wood burning stoves 2.0*
The moose likes JSP and the fly likes which is the Perfect way to store values from JDBC ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "which is the Perfect way to store values from JDBC ResultSet" Watch "which is the Perfect way to store values from JDBC ResultSet" New topic
Author

which is the Perfect way to store values from JDBC ResultSet

Bhavesh Sangwan
Ranch Hand

Joined: Aug 08, 2012
Posts: 57
Hi all!
What is the best way to store the retrieved values from ResultSet in any collection or we should directly print those values in JSP please explain with example
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

I am not clear about your requirement.
but here are some of my points from what I have understand.

in BD table each row should represent an object . if there is multiple row values, then put it in appropriate collections and transfer to view.

*choosing a appropriate data structure is depends on your business scenario.
Bhavesh Sangwan
Ranch Hand

Joined: Aug 08, 2012
Posts: 57
thanks sir... actually my question is simple but still confusing that .. which is the best collection to store result set objects to transfer to a jsp... should we use modal java class or we should directly print values in jsp using tables like elements... That is...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Result sets should never make their way out of the model layer. Always copy the data into Java classes as soon as possible and free the database resources.

What kind of Java collections are best depends wholly on the nature of the data and the business needs. There's no "one size fits all".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
caleb momanyi
Ranch Hand

Joined: Jun 17, 2012
Posts: 43

I usually get each Row from the ResultSet and store it in an Object then add all the Objects to a collection which i can then use easy in presentation using the JSTL Expression Language
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Another approach might be to use a tool like hibernate to abstract away the SQL, and only deal with objects.

Bhavesh Sangwan
Ranch Hand

Joined: Aug 08, 2012
Posts: 57
sir I'm getting a row from ResultSet and now I want to put that record in HTML table with a checkbox on first column setting value=ID which is coming from resultset
caleb momanyi
Ranch Hand

Joined: Jun 17, 2012
Posts: 43

is it working? I mean, I don't know if that's a question or a declaration of the path too have chosen to follow.
Bhavesh Sangwan
Ranch Hand

Joined: Aug 08, 2012
Posts: 57
Actually this a question ... I want to display checkbox in JSP in front of a row which I'm getting from database Result Set. So the question is How to set the value of check box equal to "id" field which is coming along with database records....
caleb momanyi
Ranch Hand

Joined: Jun 17, 2012
Posts: 43

you use expression language to set the the checkbox value as value="${object.id}"
eg if your input is like below
<input type="checkbox" name="id" value="12345678" />

you can set the value dynamically to that coming from server with ${objectFromServer.id}

your object from server must have a getter method that returns id. I hope that was clear enough an explanation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which is the Perfect way to store values from JDBC ResultSet
 
Similar Threads
jsp + jdbc
resultset
Jlist problems
Is ResultSet is serializable ??
Generic Value Object for data returned by Multiple resultsets