-->
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.  [ 5 posts ] 
Author Message
 Post subject: Common SQL issue.... apostrophe ( ' )
PostPosted: Wed Dec 21, 2005 12:54 pm 
Newbie

Joined: Tue Dec 20, 2005 12:10 pm
Posts: 3
Hi GUys I am facing a problem in my SQL query..when I use apostrophe (')

Explaination:
I want to search Java's in the search crieteria

so my SQL looks like

I used java's in my search textbox and following broblem is created in the

QUERY:
sql=
select distinct project from Project as project where project.projectStatus.projectStage = 1 and ( project.deleted is null or project.deleted <> 1 ) and ( project.inactive is null or project.inactive <> 1 )and ( project.additionalSkills like '%java's%' or project.summary like '%java's%' or project.version like '%java's%' or project.projectRequirements like '%java's%' ) Order By project.id

Code:

Session s = null;
s = getSession();
s.find(sql);

ERROR:
Could not execute query
java.sql.SQLException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's% ' or project.summary like ' %java 's%' )or(project0_.VERSION like '%java' s% ' at line 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)

Solution I tried:

I tried replacing ( ' ) with \' using standard String.replaceAll() method

using the following code .

Session s = null;
s = getSession();
s.find(sql.replaceAll("'", "\'"));


but still get the same error ...I think the find method is again using the (') as it is ... any idea or solution will be highly appreciated.


Awais Bajwa
awaisbajwa@gmail.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 3:21 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Um, this is one of the points of using parameters...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 1:56 am 
Newbie

Joined: Fri Aug 13, 2004 12:49 pm
Posts: 10
Try using two ' symbols inside the literal like - '%java''s%'


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 2:34 am 
Newbie

Joined: Tue Dec 20, 2005 12:10 pm
Posts: 3
THanks guys .....for your inputs .. but i am able to find the solution yet!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 22, 2005 2:54 am 
Newbie

Joined: Tue Dec 20, 2005 12:10 pm
Posts: 3
THanks guys .....for your inputs .. but i am able to find the solution yet!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.