Is there any way I can write (copy-paste) nicely-formatted SQL queries in Java string literals using Eclipse?

前端 未结 7 1502
情深已故
情深已故 2020-12-29 05:43

When I wish to use SQL queries in Java, I usually hold them in final String variables. Now, when the string is too large, it goes out of page breadth, and we either have to

7条回答
  •  -上瘾入骨i
    2020-12-29 06:03

    Here's a creative solution if you don't mind the extra whitespace in generated SQL output:

    Step 1: Paste

    enter image description here

    Paste your formatted SQL statement verbatim into your Java file

    Step 2: Write opening quotes

    enter image description here

    Notice the highlighted button, the sixth from the left. That's the awesome "Block Selection Mode" (Alt-Shift-A on Windows). It lets you write opening quotes on each selected line at the same position

    Step 3: Write closing quotes and concatenation

    enter image description here

    Apply the same technique for the closing quotes and the concatenation sign (+)

    Step 4: Fix the semi-colon

    enter image description here

    No comment needed here.

提交回复
热议问题