This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Special characters in hql" Watch "Special characters in hql" New topic
Author

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 )

Thanks!
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,
Reehan
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Use parameter binding.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Special characters in hql
 
Similar Threads
How to update multiple columns in Hibernate(using HQL query)?
Hibernate performance issues using huge databases
left outer join *= how make compitible in HQL
Hibernate Query column number mismatch
Help with HQL Insert and Joins using Hibernate 3 / JPA