aspose file tools*
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 Soft Skills 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
Author

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);
Trace.info("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 (moResultSet.next()) {
// retrieve and print the values for the current row
Trace.info("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: http://aspose.com/file-tools
 
subject: Viewing contents of a result set