Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling special character in HQL

 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am building HQL dynamically as below.



But the problem i am facing is that the thatre city contains one single quote because of which my HQL is not getting build correctly.



Is there any way to handle this situation instead of manually escaping single quote ?
 
Claudiu Chelemen
Ranch Hand
Posts: 75
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

First off, I don't think it's a good idea to concatenate holdOverSearchCriteriaTO.getTheatreCity() like this, wouldn't you rather be on the safe side and use bind parameters ?
Secondly, for the question at hand, you may use the escapeSql method from StringEscapeUtils to escape the problematic characters.

Cheers,
Claudiu
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic