This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes how write code to escape sql comments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how write code to escape sql comments" Watch "how write code to escape sql comments" New topic
Author

how write code to escape sql comments

majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
Hi,
I want search for some strings in lot of sql files, could you please show me how to escape the sql comments like this :

---------------------------------------------
this package declaration is used to declare record types used by other
--functions
-- t_check_list is used in FN_SUBPLAN_CHK
---------------------------------------------

Thanks
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
See Apache Commons StringEscapeUtils. It has what you need and it's pretty darned simple.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
majid nakit
Ranch Hand

Joined: Jun 26, 2001
Posts: 164
Hi, and thank you for your help, I just read the API of StringEscapeUtils, but don't understand what to use to escape comments in sql.
Please I will appreciate if you can give me an example.
thanks
Srikanth Ramu
Ranch Hand

Joined: Feb 20, 2007
Posts: 76
I guess you want to remove all the comments from a file containing sqls then search for the string. You may read the file line by line and check if the line starts with SQLs (SELECT, INSERT etc) add the lines to a StringBuffer till you reach the delimitor (semicolon,go,new empty line etc ). You might need to handle cases if comments appear with 1 sql statement. hope this helps
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Oops, my bad on StringEscapeUtils. I went by the topic title, not by the example.

I've done just what Srikanth suggested when reading SQL statements from a file. Read past the comments, read and concatenate lines until you find a semicolon.

One time I had a convention of a name for the statement in the comments. I kept all the statements in a map keyed by statement name. Then it looked more like:

Is that the kind of thing you need?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how write code to escape sql comments
 
Similar Threads
Special characters not appearing on JSP page
how to perform split operations for special characters ~!^* etc..?
Escaping special characters
How to do a SELECT WHERE a LIKE b when b has a '%'?
Escape sequence inside javascript