File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Escaping Sequence problem.

 
Harish Chandra Durgapal
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(to_char(h.secsaledate,'"WEEK1M"MMYYYY'),15)docdt,
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 b.company='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),
rpad(to_char(h.secsaledate,'"WEEK1M"MMYYYY'),15),
rpad('CL12',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.
Thanks
harish.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joanne Neal
Rancher
Pie
Posts: 3742
16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I were you I'd build the statement using a StringBuffer/StringBuilder. It will make it a lot easier to maintain.
e.g.


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
Posts: 1923
Linux Postgres Database Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,Joanne,Stefan

Thanks a lot .It solved my problem.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic