• 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: 34863
369
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