Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java properties file using multiple lines for one property

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 ?

like image 914
NimChimpsky Avatar asked Jul 23 '12 10:07

NimChimpsky


People also ask

How do you write multiple lines in properties file?

You add a slash ("\") to continue the value on the next line.

How read properties file line by line in Java?

Java Read File line by line using BufferedReader We can use java. io. BufferedReader readLine() method to read file line by line to String. This method returns null when end of file is reached.

Can we have multiple application properties?

So you can create two applications. properties files one for the original database and the other for the test database which you use during development.


1 Answers

Use \ at the end of the line like

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

Also, beware of any trailing whitespaces since Java looks for consecutive backslash+linebreak when assembling the lines.

Put differently : The backslash has to be the very last caracter on the line before the line break.

like image 99
Manoj Avatar answered Sep 22 '22 11:09

Manoj