I have a very long SQL statement inside of a Java String. In eclipse, how can I easily get the SQL statement’s text without the Java String syntax? I’ve been manually removing it, but in IntelliJ Idea, it’s possible for one to get the text without having to do any manual formatting work to remove the Java String syntax (such as " and + characters). Does Eclipse have a similar feature?
As an added bonus, I would ask if it were also possible to get the string with the newlines put in place as it was formatted in the IDE, even if no \n characters were present in the string itself.
Depending on your SQL client, it could have this feature.
I know that TOAD has this feature built-in. I also remember Squirrel having it.
So when pasted into the SQL editor of TOAD, the code is automatically extracted from the Java string syntax. I remember that it also worked with constructs like StringBuffer/StringBuilder.
See: http://dev.toadformysql.com/webhelp/Content/Editor/Convert_SQL_Embedded_SQL.htm
Or you can create a simple regexp working for your sample code, for example this jsfiddle.
It works with a regex for sql like:
The jsfiddle should output
Still it is not beautifully formatted (even if with the
<pre>tag it should preserve spaces), but your SQL IDE should help you with that, no?