This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inserting single quotes into database

 
vikas sharmaa
Ranch Hand
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting "missing comma" SQL error while inserting a String that contains single quotes in it. for example, the below insert statement code:



now, the above code will throw run time sql error because the insert statement has single quotes in manager's word as shown below:

insert into emp (detail) values ('its manager's duty.')

i guess this will be a very common problem. so, is there any standard way or in-built method to resolve the issue. please help. thank you.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try 'The manager''s duty'
Try 'The manager\' duty'

Note first example is single quote twice, not double quote.
 
Paul Clapham
Sheriff
Pie
Posts: 20183
25
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or better still, use a PreparedStatement:

That way you don't need to worry about quotes. Or date formatting, or any other SQL formatting issues. The JDBC driver takes care of all of the escaping for you.
 
vikas sharmaa
Ranch Hand
Posts: 191
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you campbell and paul.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic