This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Viewing contents of a result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Viewing contents of a result set" Watch "Viewing contents of a result set" New topic

Viewing contents of a result set

tim mahoney
Ranch Hand

Joined: Apr 19, 2005
Posts: 33
Hey guys, need some help viewing contents of a result set. I would like to view the contents of the resultset. I tried using the StrigBuffer and received a location in memory output "Contents of the resultset: >>>
oracle.jdbc.driver.OracleResultSetImpl@139eeda". How can I view the results of my query in the result set? Thanks in advance.
moResultSet = loNDBQ.getResultSet();
StringBuffer lsbSql = new StringBuffer();
lsbSql.append(moResultSet);"Contents of the resultset: >>> " + "\n"+lsbSql);
K Riaz
Ranch Hand

Joined: Jan 08, 2005
Posts: 375
getResultSet() returns a ResultSet object. You can then use this to invoke "getObject(columnNumber)" to get the resultant data.
tim mahoney
Ranch Hand

Joined: Apr 19, 2005
Posts: 33
Thanks for posting. This is the code that got it to work.
moResultSet = loNDBQ.getResultSet();
while ( {
// retrieve and print the values for the current row"Contents of the resultset: >>> "+ "\n"+moResultSet.getObject(1));
[ May 17, 2005: Message edited by: tim mahoney ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Your example only showed the first column. Was that all you needed? For all the data it would look more like:

You might want to expand this idea to make a little utility that will dump the contents of any result set. You could use it in testing and debugging:

System.out.println( new ResultSetDumper( resultSet ).toString() );

It would be a cool way to explore the resultset object, too. For example you could get the metadata and build column headings, pad the values to the column width, use the datatypes to decide if you'd like to left or right justify the data in each column. Hmmm, this starts to look like a quick & dirty reporting tool. Sound like fun?

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
tim mahoney
Ranch Hand

Joined: Apr 19, 2005
Posts: 33
Sounds good Stan. Thanks for posting.
I agree. Here's the link:
subject: Viewing contents of a result set
It's not a secret anymore!