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

前端 未结 7 1501
情深已故
情深已故 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条回答
  •  北海茫月
    2020-12-29 05:58

    Actually a really good question, I often wonder about that as well. One tip I can give you is using the following:

    //@formatter:off
        private static final String QUERY = 
        "SELECT t.* " +
          "FROM table t " +
         "WHERE t.age > 18";
    //@formatter:on
    

    It does not convert a SQL query into a Java String literal, but it keeps Eclipse from reformatting your String awkwardly unreadable.

提交回复
热议问题