This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

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
 
Similar Threads
Need a Help!!
Before insert Trigger
database connection
JSTL SQL dataParam
how to convert .csv files into sql server files using java