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

inserting text with single and doubl quotes

 
Gul Khan
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
When i try inserting a text with quotes single or double. the Db generates error on the sql statement. Can someone plz help me how to implement it so it can insert the quotes in text and not show errors.
Thanks
Gul
 
Bhupendra Malviya
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gul,
Are you using "preparedStatement" to insert values.
If not then give it a shot.I didnt get any error using Prepared Statement on Ms Access.
 
Gul Khan
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bhupendra
I am not using prepared statement. and to move to that i would have to change alot of modules. Is there any way i can do it in normal Statement.
I am using MySQL by the way.
 
Bhupendra Malviya
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gul,
The only other method that I can think of is ,
You will have to parse your text in search of single quote(') and insert a escape character for java and your database language.
eg: the following peice of code works for Access/Oracle database(Sorry i am not conversant with Mysql)
query.executeUpdate("Insert into users values('Bhupi\''s')");
where \(back slash) is the escape character for java
'(Single Quote) is the escape charcter for Oracle Sql
and second '(Single Quote) is the quote in the actual text
Hope it solves ur problem let me know at this forum or mebhupendra@yahoo.co.in
 
Gul Khan
Ranch Hand
Posts: 173
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
the single quote escape character also works with MySQL. Now let's c which option is better.. change all statements to prepared statements at more than a 100 places or search for quotes in every form input at about the same number of places. I think i should go with the prepared statement, more beneficial on long run.
Thanks again for the help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic