Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which is the Perfect way to store values from JDBC ResultSet

 
Bhavesh Sangwan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
caleb momanyi
Ranch Hand
Posts: 43
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1712
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another approach might be to use a tool like hibernate to abstract away the SQL, and only deal with objects.

 
Bhavesh Sangwan
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic