File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Apostrophe Problem in String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Apostrophe Problem in String" Watch "Apostrophe Problem in String" New topic
Author

Apostrophe Problem in String

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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


GenRocket - Experts at Building Test Data
Roy Ben Ami
Ranch Hand

Joined: Jan 13, 2002
Posts: 732
im sure our moderator knows the answer for that one !
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Actually, I figured it out. PreparedStatement instead of Statement.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Jan 13, 2002
Posts: 732
sorry David, i only meant it as a freindly joke.
no pan intended.
point taken.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

and I completely took it as a friendly poke!
No stress caused!

Dave.
 
 
subject: Apostrophe Problem in String