Data-driven applications need to generate SQL from time to time. Usually, we leverage things like stored procedures or ORM tools to keep our code sane, but from time to time, we might hard code our SQL statements. You sacrifice some flexibility for some transparency into what your code actually does to the database.

Sometimes, however, writing SQL is just too darn readable. Adam’s co-worker has a better way:

 private static String getItemInsertSql() {
   StringBuilder sb = new StringBuilder();
   sb.append(INSERT); sb.append(RSS_ITEM_TABLE_NME);
   sb.append(OPEN_PAREN); sb.append(NME_PUBDATE_COLUMN);
   sb.append(COMMA); sb.append(RECORDING_ID_COLUMN_NAME);
   sb.append(COMMA); sb.append(CHANNEL_ID_COLUMN_NAME);
   sb.append(COMMA); sb.append(NAME_OF_ENABLED_COLUMN);
   sb.append(COMMA); sb.append(TITLE_COLUMN);
   sb.append(COMMA); sb.append(SUBTITLE_COLUMN);
   sb.append(COMMA); sb.append(DESCRIPTION_COLUMN_NAME);
   sb.append(COMMA); sb.append(AUTHOR_NAME_COLUMN);
   sb.append(COMMA); sb.append(KEYWORDS_COLUMN);
   sb.append(CLOSE_PAREN); sb.append(VALUES); 
   sb.append(OPEN_PAREN); sb.append(NOW);
   sb.append(COMMA); sb.append(QUESTION);
   sb.append(COMMA); sb.append(QUESTION);
   sb.append(COMMA); sb.append(QUESTION);
   sb.append(COMMA); sb.append(QUESTION);
   sb.append(COMMA); sb.append(QUESTION);
   sb.append(COMMA); sb.append(QUESTION);
   sb.append(COMMA); sb.append(QUESTION);
   sb.append(COMMA); sb.append(QUESTION);
   sb.append(CLOSE_PAREN);

   return sb.toString();