File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 and Relational Databases
Bookmark "how to insert a value with aphostophy character" Watch "how to insert a value with aphostophy character" New topic

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

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

Joined: May 26, 2003
Posts: 33107

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Srinivas Rao

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:
subject: how to insert a value with aphostophy character
It's not a secret anymore!