<< Previous | Home

How do I get a stack trace in a String?

It comes up every now and then: someone wants a stack trace in a String. They're probably wrong; if they're trying to analyze the stack trace, there are mechanisms in the Throwable to do that without creating a String and parsing it, but just in case... here's how you get a stack trace from an exception in a String.

Read more...

Tags :

Horrible JDBC Code and What's Wrong With It

Ah, Efficiency: Thou art a goddess who deserves worship, adulation, sacrifice, but thou art also a goddess who gets said worship, adulation, and sacrifice in all the wrong ways. Here's some JDBC code validating a login, trying to be good code (I think!)... that gets it wrong in almost every way possible.

Read more...

Tags :

Are JDBC statements portable across databases?

Ah, JDBC. Sometimes, people want to write JDBC code, because SQL is friendly and safe; then they discover that they actually don't want to deploy on MySQL after all, and they run into problems. The question is usually formed in this way: "If I write my SQL in a prepared statement, is it going to work the same way in $OTHER_DATABASE?"

Read more...

Filtering characters from a Reader

It's an occasionally legitimate question: "How do I filter content from a Reader?" There're related questions for Streams, too. Here's an example of a simple Reader class that shows how to remove specific characters from a Reader.

Read more...

How can I create a maintenance window for my web app?

Every so often, web applications need maintenance. Yes, even web applications. It's okay - no need to reach for your security blanket. The problem that's come up is: What's a good way to redirect requests during a maintenance window to an error page? As usual, there are multiple answers.

Read more...

How can I automatically expire data from a database?

Another fairly common question: how can I expire data from a database? This is a case of applying lipstick to a pig: there are ways, to be sure, but the real problem is that you're using a database - a permanent datastore - to handle data that's short-lived.

Read more...

My data structures have changed - how can I migrate my data model?

Sometimes, people design data structures, persisted entities, only to find that - gasp! - their data structures are more fluid than they expected. When all of your data is transient - meaning that it can be destroyed safely - that's no big deal, because you just drop the tables in question (or the whole database) and start over. (Sound familiar, Rails fans?) Sometimes, that's not enough - so what do you do?

Read more...

How do I send mail with Java?

You send mail in Java with one of two APIs, basically: JavaMail and Commons-Email. People who use JavaMail fit in one of three categories: they don't know about Commons-Email, they are doing bulk mail and know what they're doing, or they're gluttons for punishment. Here's a class that shows how to send mail with both JavaMail and Commons-Email, for the case of sending to a single address.

Read more...

Tags :