File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Escaping Sequence problem. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Escaping Sequence problem." Watch "Escaping Sequence problem." New topic

Escaping Sequence problem.

Harish Chandra Durgapal

Joined: Mar 01, 2006
Posts: 14
Hi All,
Last time I really stuck with a simple String initilization problem..
I have initilise a String variable with a large sql query as follow.....

String query="select rpad('WS'||substr(h.wdcode,1,7),15) wdcode,
rpad('S'||substr(d.brandcode,1,4)||decode(b.unitsperpack,5000,5,7000,1,10000,2,12000,3,6000,4,0),15) brandcode,
rpad('CL12',15) trntype,lpad(to_char(sum(d.retailer),'999999999'),15) qty
from basis.dp_secsaleheader h, basis.dp_secsaldetail d, basis.brandmstr b
where h.secsaleheadercode = d.secsaleheadercode and d.secsalecategorycode=1 and'GPI' and d.brandcode = b.brandcode and to_number(to_char(h.secsaledate,'DD')) <=7 and h.secsaledate >= to_date'01092006','DDMMYYYY') and h.secsaledate <= to_date('30092006','DDMMYYYY')and d.retailer>0 and substr(h.wdcode,1,2) ='02' group by rpad('WS'||subst(h.wdcode,1,7),15),rpad('S'||substr(d.brandcode,1,4)||decode (b.unitsperpack,5000,5,7000,1,10000,2,12000,3,6000,4,0),15),
This gives me a error String literal is not properly closed by double quote.
Can any one guide me how to initilise this query to a String variable.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24195

Is this all on one line, or are those line breaks really in your code? You have to have it all on one line in the code. I also can't tell if you have actual double quotes inside the String or not; if you do, then you need to put a "\" backslash before each one.

[Jess in Action][AskingGoodQuestions]
Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
If I were you I'd build the statement using a StringBuffer/StringBuilder. It will make it a lot easier to maintain.

As Ernest said, there's probably some double quotes in there which you will need to escape.

[ October 04, 2006: Message edited by: Joanne Neal ]
[ October 04, 2006: Message edited by: Joanne Neal ]

Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

And I would put linebreaks and tabs into the sql, to make debugging more convenient:

How readable is that?
[ October 04, 2006: Message edited by: Stefan Wagner ]
Harish Chandra Durgapal

Joined: Mar 01, 2006
Posts: 14
Hi Ernest,Joanne,Stefan

Thanks a lot .It solved my problem.
I agree. Here's the link:
subject: Escaping Sequence problem.
It's not a secret anymore!