File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Failed to insert text with quotes

satish jupalli
Greenhorn

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.
Ex:
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.
regards
satish
David O'Meara
Rancher

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+ '"')";
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Failed to insert text with quotes