Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String can not have break line?

Status
Not open for further replies.

cfmx

Programmer
Feb 26, 2003
4
US
I'm very familiar with Coldfusion language and now trying to learn Java. Java gives me so much headache...

I have a question about sql string. Is there way to read this kind of query from the java? Of course java throws the error here but I'm hoping that there's way to parse this sql string like below.

sqlStr = "
SELECT a
,b
,c
,d
,e
FROM tableA
WHERE user_id = '"+ userID +"'
"
 
You can't put line breaks in the middle of a String in your source code.

String s = "Hello
there"; // will generate a compile error
however,

String s = "Hello" +
"there"; // will work
 
Are you specifically looking for out put from java that willl span a number of lines, but with only 1 String?

ie
Code:
String "Hello" +
       "there";
will be outputted as "Hello there".
but if you want it to be outputted as
"Hello
there"
ie on two lines

then you might try
Code:
String "Hello \n there"

the \n isthe newline character, \t is a tab -------------------------------------------
There are no onions, only magic
-------------------------------------------
 
Thank you for quick response.
However, I need more help if you can help me.
I know that

String sqlStr = "select name " +
"from tableA " +
"where name = '" + username + "'";

is the only way to make work on sql string. My goal is make sql statement more readable. so if there's way to read like

String sqlStr = "select name
from tableA
where name = '" + username + "'";

that will be great for me. it doesn't have to be string, it can be any object as long as i can have some sql string as above(input). i tried to used sql xml file but i figured that this creates too much headache. i'm not sure anybody tried do this kind of sql statement in java...
 
then you want something much like what jfryer has proposed.

String sqlStr = "select name \n" +
"\tfrom tableA \n" +
"\twhere name = '" + username + "'";

that will give you line breaks at the end of each line and tabs at the beginning of every line but the first, which should help for formatting. Liam Morley
lmorley@gdc.wpi.edu
"light the deep, and bring silence to the world.
light the world, and bring depth to the silence."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top