GeeCON Prague 2014*
The moose likes JDBC and the fly likes Insert with ' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Insert with Watch "Insert with New topic
Author

Insert with '

Mike Yu
Ranch Hand

Joined: Nov 17, 2001
Posts: 175
Hi,
How can I insert a string with ' into a table in DB2?


Thanks,<br />Mike
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Originally posted by Mike Yu:
Hi,
How can I insert a string with ' into a table in DB2?

Use a PreparedStatement ( setString() method ) and it will take care of it for you. If you need to use a statement you have to create a routine that escapes it with the DB2 escape character. Assuming it is 2 single quotes, this routine would work for you:

Jamie
 
GeeCON Prague 2014
 
subject: Insert with '