Even the Pros Make Silly Mistakes

GeneralDev.jpg

I was coding fast and furious today - trying to get the back-end persistence into a web servlet I was writing. The requests were being handled perfectly, the first-line persistence was great in an in-memory H2 database, and the back-end MS SQL Server database was the saving, I just wasn't able to load the data from the back-end store on restart. Something was causing the servlet to have problems on startup.

In order to get the last 14 days of data from the back-end, I had code that looked like this:

  // create the Calendar with today's date
  GregorianCalendar    start = new GregorianCalendar();
  // set it back two weeks for the SQL statement
  start.add(Calendar.DAY_OF_MONTH, -14);
  SimpleDateFormat  fmt = new SimpleDateFormat("yyyy-MM-dd");
  // build up the SQL
  String  sql = "select * from portfolio where acquired > '" +
                fmt.format(start) + "'";

And for about 20 mins I was wondering what on earth is wrong with the formatter that's causing the problem? I was looking at the spelling of the class... the format string... all kinds of things.

And then it hit me. Duh!

I couldn't believe that I'd spent all that time looking at the code and not realizing that I was passing in the wrong argument to the formatting. Funny thing was, it wasn't caught by the compiler. Wild.

Just goes to show that even pros make silly mistakes.