java properties file using multiple lines for one property

Viewed 34459

I am storing sql in a properties file and injecting it using spring this works :

someSQL = select result from myTable where y = 2 and x = ? order by z

but for readibility I want this :

    someSQL = select result 
              from myTable 
              where y = 2  
              and x = ? 
              order by z

What is the correct text formatting I need to use ?

4 Answers

use \ for new line and make sure that there is one space before each \

   someSQL = select result \
              from myTable \
              where y = 2  \
              and x = ? \
              order by z \

If One space is not given output will be like this

 someSQL = select result\
              from myTable\
              where y = 2\
              and x = ?\
              order by z\
    someSQL=select resultfrom myTablewhere y = 2and x = ?order by z
              

this will cause

Java level : java.sql.SQLSyntaxErrorException

and DB level Missing Keyword

Related