This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Insert with '
 
Similar Threads
Game on SQL
XML, flat files to database
Approach for "Say", part a
Transaction management
JSP and Access