Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can insert Single Quot(') in oracle databse by java Program

 
Parshuram Walunjkar
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am trying to store a string like
String str = "Thank's";
In Oracle database it gives SqlException Because of singleQuot .
So please tell me how to store such type of string in database.
Plaese help me.
Regards
From Parshuram Walunjkar
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
YOu need to use a PreparedStatement instead of just Statement. That will handle escape characters.
 
SAFROLE YUTANI
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you dont use a PreparedStatement, then you must always escape any "'" with "''". In other words, if I want to update a row that contains a VARCHAR type column named PHRASE with the following data...
Hello baby, it's party time!
...then you must use....
UPDATE someTable set PHRASE = 'Hello baby, it''s pary time!'
If you use PreparedStatement, then the database vendor driver will handle the escaping for you, among other things which it will also handle, that's why using PreparedStatement is the preferred method.
Hope that helps.
SAF
[ February 27, 2002: Message edited by: SAFROLE YUTANI ]
 
Abdul Salam
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing to keep in mind is 'Prepared statements'
are not intended to escape characters.They serve a different purpose.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic