Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ex.printStackTrace() to String

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

I need to convert a ex.printStackTrace into a String so that it can be used in a SQL query to insert it into a table.

This needs to be done from a JSP (inside a try/catch)

Any clues?

Cheers
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at:

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Throwable.html#getStackTrace()


All throwables have the getStackTrace method which returns an array of StackTraceElement. You can iterate through that array and build a string with any of the the properties that you like.

Even better, you can put each property into it's own table row.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this out:

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers guys, I went for the secoind option in the end. works a treat, even get the formatting back when returning SQL results.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic