how to store a string containing single/double quotes

HI,

When storing a string from a textarea into a access database i have problem when the string contains single quotes or double quotes. The value is not updated in the database. My insert query is

insert into tablename values('"+request.getParameter("desc")+"')");

thanks in advance.

baskar

[331 byte] By [baskibv] at [2007-9-26 2:26:46]
# 1

use preparedStatement :

PreparedStatement pStmt = null;

String query = "insert into tablename values(?);

pStmt = conn.prepareStatement(query);

pStmt.setString(1, request.getParameter("desc"));

pStmt.executeUpdate();

hope this will help you.

Badr.

zbadr at 2007-6-29 9:40:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

If you use two single quotes when you submit a query it is tranlated to one inside the text field.

So if I had a part of an SQL statement along the lines of

" SET house='Dave's House' " it will crash but if I change that to "SET house = 'Dave''s House' " the database record for house will come out as "Dave's House".

Breakfast at 2007-6-29 9:40:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...