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 Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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
 
 
subject: Insert with '
 
It's not a secret anymore!