Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Failed to insert text with quotes

 
satish jupalli
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you tried using a PreparedStatement instead? It makes problems like that go away.
 
Amy Phillips
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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+ '"')";
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic