wood burning stoves 2.0*
The moose likes JDBC and the fly likes Failed to insert  text with quotes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Failed to insert  text with quotes" Watch "Failed to insert  text with quotes" New topic

Failed to insert text with quotes

satish jupalli

Joined: Apr 06, 2003
Posts: 10
Hi all,
Im unable to insert text data into a table when the text im trying insert has quotes.
String sql1="INSERT into project VALUES ('"+project+"','"+desc+"')";
int status1=st1.executeUpdate(sql1);
the above code is working fine as long as im inserting text data with out quotes. However, its failing when im triyng to insert text data which contains quotes. How can i insert text data that has quotes into a table.
Im using MS Access as back end.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

have you tried using a PreparedStatement instead? It makes problems like that go away.
Amy Phillips
Ranch Hand

Joined: Apr 02, 2003
Posts: 280
Hi Satish, welcome to the Java Ranch
I haven't tried this but I know it works in ASP so I expect it should also work in Java...
You need to enclose the actual text with single ' so you end up with
String sql1="INSERT into project VALUES ('"' +project+ '"','"' +desc+ '"')";
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Failed to insert text with quotes
Similar Threads
How to handle comma in the text field?
What exactly we mean by Precompiled SQL Statement
is this SQL Stament correct ???
extracting from text field
Display tag libray - export appending quotes