File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Insert with ' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Insert with Watch "Insert with New topic

Insert with '

Mike Yu
Ranch Hand

Joined: Nov 17, 2001
Posts: 175
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:
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:

Don't get me started about those stupid light bulbs.
subject: Insert with '