-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: escaping single quotes in database columns
PostPosted: Tue Dec 21, 2004 10:28 am 
Newbie

Joined: Tue Dec 21, 2004 10:19 am
Posts: 3
Hi all,

My application uses the Sybase database, and to insert text with a single quote I've always escaped the quote by adding a second single quote. The second quote does NOT appear in the db, it's just an escape char so Sybase knows the first quote is part of the text and not part of the SQL statement. My problem is that I can't figure out how to escape a single quote when using hibernate. If I escape the text the way I do when writing directly to the db, both single quotes appear in the database. And if I just use one single quote the SQL statement does not execute correctly.

Any help would be greatly appreciated!

Thank you,
Rachel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 10:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Use parameter placeholders and let the JDBC driver do the escaping


Top
 Profile  
 
 Post subject: need some help with parameter placeholders
PostPosted: Tue Dec 21, 2004 12:08 pm 
Newbie

Joined: Tue Dec 21, 2004 10:19 am
Posts: 3
Thanks so much for the speedy reply. I can't seem to find much documentation on parameter placeholders? Sorry, I am new to hibernate and trying to edit existing code. I assume this is something along the lines of a java PreparedStatement, using the "?" ... but I can't seem to find an example anywhere?

Thanks!
Rachel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read the reference documentation, its called "parameter binding".


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 12:13 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please read the reference manual: http://www.hibernate.org/hib_docs/reference/en/html/manipulatingdata.html#manipulatingdata-querying


Top
 Profile  
 
 Post subject: parameter binding during a saveOrUpdate ??
PostPosted: Tue Dec 21, 2004 1:03 pm 
Newbie

Joined: Tue Dec 21, 2004 10:19 am
Posts: 3
I read the documentatin you sent, and I can see how one could use parameter binding while querying the db. But what about when one saves or updates an object? The code I currently use goes like this:

Code:
Group groupObject = new Group("name'");
Session hs = HibernateSessionFactory.getThreadLocalSession();
Transaction tx = hs.beginTransaction();
hs.saveOrUpdate(g);
tx.commit();




It seems the available save and update functions only take an object and I don't see how I can specify any SQL in this instance? Sorry to be so dense.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 1:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that stuff should work since hibernate will use parameter binding on its own in this case...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 21, 2004 1:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
There is of course no need to escape stuff manually on your object properties when you are just doing a .save() - Hibernate wil handle that, or rather the JDBC driver will.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.