This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting names with single quote using INSERT statement

 
Suresh Kanagalingam
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Works great.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic