Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Escaping single quote in string

Status
Not open for further replies.

jlynch1

Technical User
Dec 20, 2001
100
IE

How do I replace a single quote ' with two single quotes '' so I can insert information from a form into a text field in an MS Access database.

The replace method of string only lets me replace a single character with a single character...

How can I get around this ??
 
how would I specify a single quote as a regular expression as required by that function.

public String replaceAll(String regex, String replacement)
 
A better solution is to use PreparedStatement.
e.g.
java.sql.Connection conn = ......

java.sql.PreparedStatement ps=conn.prepareStatement("insert into mytable (field1,field2) values (?,?)0);
ps.setString(1,yourclass.getYourField1());
ps.setString(2,yourclass.getYourField2());
ps.executeUpdate();
If you use PreparedStatement instead of Statement there is no need care about ' or '' s.
Salih Sipahi
Software Engineer.
City of Istanbul Turkey
ssipahi@yonbilgi.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top