• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Apostrophe Problem in String

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
among many other fields, I have a text area that I am getting and entereing into an SQL database. The problem is that if you use a contraction like CAN'T or DON'T or WON'T, in other words, inlcuding an apostrophe in the text field, SQL throws an exception because String literals are added to the DB using ' '. Does anyone know of a work around without telling the users they can't use certain characters in typing?
Thanks
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im sure our moderator knows the answer for that one !
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I figured it out. PreparedStatement instead of Statement.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roy Ben Ami:
im sure our moderator knows the answer for that one !

Hmm, trouble maker, eh?
You could just paste a link instead

(If you did a search on my name a PreparedStatement you'd probably get stacks of hits. What can I say, I'm a fan. )
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry David, i only meant it as a freindly joke.
no pan intended.
point taken.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and I completely took it as a friendly poke!
No stress caused!

Dave.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic