aspose file tools*
The moose likes JDBC and the fly likes how to insert a value with aphostophy character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to insert a value with aphostophy character" Watch "how to insert a value with aphostophy character" New topic
Author

how to insert a value with aphostophy character

smitha mano
Ranch Hand

Joined: Sep 26, 2005
Posts: 70
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: May 26, 2003
Posts: 30776
    
157

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Srinivas Rao
Greenhorn

Joined: Aug 05, 2004
Posts: 14
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");
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to insert a value with aphostophy character