• 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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!