File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Special characters in hql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Special characters in hql" Watch "Special characters in hql" New topic

Special characters in hql

Ryan Waggoner
Ranch Hand

Joined: Jun 27, 2007
Posts: 75
Hey guys,

I have a bunch of hql statements that my site uses. Often these queries are made from input on the web page. For something like a description field it is not unusual to have an apostrophe (') in the query. SQL does not like this one bit, and yells at me for it every time.

Any suggestions on how I would go about putting an escape character in for an ' every time it appeared in the query?

(with out putting an if statement on each hql statement )

Reehan Lalkhanwar
Ranch Hand

Joined: Jun 16, 2007
Posts: 106
Append a special character before the quote and tell the DB that as the escape character.

Thank you,
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Use parameter binding.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
I agree. Here's the link:
subject: Special characters in hql
It's not a secret anymore!