This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to insert a value with aphostophy character

 
smitha mano
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to insert a value to the table like this
using SQL statement
direct entry of SQL

insert into values('St. Mary's Church');
here i neeeded to use aphostophy
how to solve this
please give me the solutions
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option 1) create your own parse to escape apostrophe and any other special charaters for your specific database, and then write that code from scratch if you ever change databases.

Option 2) Use a PreparedStatement (it does all the escaping for you)
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Smitha,
If you are using JDBC, use a PreparedStatement. If not, post what database you are using. It's different for each one. For example, in Oracle you set an escape character.
 
Srinivas Rao
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
replace each single quote within a string with two single quotes when using Statement. Otherwise Preparestament.setString() will work for you.

ex: insert into values("St. Mary''s Church");
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic