This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes JSP and the fly likes ex.printStackTrace() to String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "ex.printStackTrace() to String" Watch "ex.printStackTrace() to String" New topic

ex.printStackTrace() to String

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
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?

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Look at:

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.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10394

Try this out:

[My Blog] [JavaRanch Journal]
Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Cheers guys, I went for the secoind option in the end. works a treat, even get the formatting back when returning SQL results.
I agree. Here's the link:
subject: ex.printStackTrace() to String