-->
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.  [ 6 posts ] 
Author Message
 Post subject: Query using String Array in IN cluase
PostPosted: Mon Dec 19, 2005 8:34 pm 
Newbie

Joined: Mon Nov 28, 2005 1:04 am
Posts: 9
Hi friends,

I am trying to execute a query by passing string array to IN cluase. But I am getting Data type mismatch error message. Here is my query.

Code:
String Sql =
         "select ocorder.Id, ocorder.Custid"
        + " from Ocorder ocorder where ocorder.Id in (:ordnumarray)";
         


Here I am passing ordnumarray as "302000097, 302000098"

Is there anything wrong in this query?

Please guide me.

thanks,
gautam


Top
 Profile  
 
 Post subject: Quotes?
PostPosted: Mon Dec 19, 2005 9:13 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Have you omitted the quotes accidentally? An array of strings should appear in SQL as ('302000097', '302000098'). Without the quotes, it's an array of ints.. hence type mismatch.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 11:36 pm 
Newbie

Joined: Mon Nov 28, 2005 1:04 am
Posts: 9
Thanks for your reply.

I changed it to ('302000097', '302000098') still it is giving the same message as follows,

Code:
net.sf.hibernate.JDBCException: Could not execute query
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1539)
Caused by: java.sql.SQLException: Data type mismatch.
   at com.ibm.as400.access.JDError.throwSQLException(JDError.java:381)


if I give two seperate strings with query.setString("order1", "302000097") and query.setString("order2", "302000098") the query is working. But If I give these two order numbers in single a string(by separating with quotes) it is not working.

Can you help me.

thanks,
gautam


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 19, 2005 11:44 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Ah I'm caught up. I thought you were building the string yourself.

Just change the java code you're using to populate :ordnumarray to setParameterList instead of setParameter/setString.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 12:44 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

How about using Criteria here?
Some thing like this

Criteria critetria= session.createCriteria(YOURCLASS.class);
critetria.add(Expression.in("Id", IDLIST));
List list = critetria.list();

Any Suggestions?????????

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 2:02 am 
Newbie

Joined: Mon Nov 28, 2005 1:04 am
Posts: 9
Hi tenwit.

Your answer is awesome. This solved my problem. I have given credit to you. Thank you very much. Keep it up.

gautam.


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