This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!