File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 10441

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
It's not a secret anymore!