• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Viewing contents of a result set

 
tim mahoney
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 375
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getResultSet() returns a ResultSet object. You can then use this to invoke "getObject(columnNumber)" to get the resultant data.
 
tim mahoney
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
tim mahoney
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds good Stan. Thanks for posting.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic