Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Querying DB and Iterating over the resultset

 
RushiKumar Bhatt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone

I am stumped at this:
I am querying my Database using HQL. This part of the process is working just fine, as when I debug, I can clearly see that the variable contains set of elements with the needed data. however, in my JSP page, when I iterate over the list, I get the funky Ljava.lang output:

[[Ljava.lang.Object;@1d5e499, some.path.action.Class@15f1ace, com.opensymphony.xwork2.DefaultTextProvider@d8f317]


Now, I understand that I need to have it output as a string, but how to do this with strut's iterator?
This is how I am iterating over the list, in my jsp page:



Here is what "myList" variable contains, once it executes the query:

myList
--elementData
----[0]
------[0]
-------- 1
------[1]
-------- This is the description
----[1]
------[0]
-------- 2
------[1]
-------- Second description


I cannot change the value from "[0]" or "[1]" to something else, as this is how they are stored in the list



Please shed some light on this
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using a bare "[n]" OGNL expression evaluates to the stack minus the top n entries, which will almost never be what you want.

Set the var of the iterator and use that:I'm skeptical that that's what the HQL would return, though; an HQL query normally returns a collection of domain objects, from which you should be able to access properties by their proper names.
 
RushiKumar Bhatt
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Mr. Newton,

That worked!!

Thank you, Sir!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic