aspose file tools*
The moose likes JDBC and the fly likes Inserting names with single quote using INSERT statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Inserting names with single quote using INSERT statement" Watch "Inserting names with single quote using INSERT statement" New topic
Author

Inserting names with single quote using INSERT statement

Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Hello,
I am writing a Java program which needs to insert names, which may contain commas, single quotes (') and so on. Currently I have a line which states as follows:
"INSERT INTO TBNAMES VALUS ('clientNumber', 'name');"
It is throwing an error when the name contains a single quote (ORA-00917 : missing comma)
Then I changed the code as follows:
"INSERT INTO TBNAMES VALUS (:clientNumber, :name);"
Now it complains that not all variables defined (ORA-01008 : Not all variables defined).
Can any one shead some light on this?
Thanks
Suresh
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

You'll have to create a method that will replace a single quote with two single quotes (escape sequence).
...OR make your life easier, and your code easier to read... use a PreparedStatement instead of statement. It takes care of the special characters(like single quotes) for you. No need for extra coding.
Jamie
[ January 25, 2002: Message edited by: Jamie Robertson ]
Suresh Kanagalingam
Ranch Hand

Joined: Aug 17, 2001
Posts: 82
Works great.
Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting names with single quote using INSERT statement