title: How to format java string to SQL syntax?
body: <p>I've searched the site but haven't found exactly what I need. I have an SQL statement</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>String unformattedSQL = "select id, name, address, zip    from   schema123.person  where name like '%stu%'";
  </code></pre>
  
  <p>I'm looking for a method like <code>formatSQL(sqlString)</code> that gives me the formatted version of my original SQL statement, such that</p>
  
  <pre class="lang-java prettyprint-override"><code>String formattedSQL = formatSQL(unformatted);
  System.out.println(formattedSQL);
  </code></pre>
  
  <p>will give me the following text (with correct indentation)</p>
  
  
  
  <pre class="lang-sql prettyprint-override"><code>SELECT id, name, 
         address, zip 
  FROM schema123.person 
  WHERE name LIKE '%stu%'
  </code></pre>
  
  <p>The original SQL statement is actually very long and is dynamically generated by another method (I cannot change this method), so there's no way I can put the SQL in an external file. After the SQL is executed, I need to put it in a log file. I want the SQL statement to be formatted in the log file.</p>
  
  <p>What is the best way to do this? And to generalize the problem, how to do this for another syntax like XML, C#, etc. Maybe something similar to Google Code Prettify but for Java ...</p>