This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use create query with having list as parameter

 
Esaki muthu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to create a query based on ceratin search condition in which i get a list at some condition in the middle of the query construction ..

I first create a query by using stringBuilder and append the string based on the various condition and in one such condition i get list and
i have appened in the sting as list and based on few conditions the query is now generated and i could not get the correct answer


I need to execute at this condition

Note : It should not give the condition like this

Query q=em.createQuery(getQuery().toString)
q.setParameter("list",list);

reply to use the list while appending query in string builder itself.

I have used and program runs but value is 0 ...as i give list as condition in query ...If i give as parameter its working correct


 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi maha muthukumar,

Welcome to CodeRanch!

Firstly, do not ever use '==' to check object equality. Always use equals method. If you have to use '==', then be extremely sure that you really need it, and that you know what you are doing.

Secondly, I didn't get how the list will be part of the query. Can you provide a sample query which contains contents of list? If you need to check if some value is on of those presents in the list, then you can use 'IN' syntax of SQL (e.g. value IN (a,b,c) etc.)

I hope this helps.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maha, and welcome to the Ranch!

I've moved your question to the JDBC forum, where you'll get more attention from people who deal with JDBC. Also, I've added code tags to the code in your post and indented it a bit to improve readability; you can do so yourself using the Code button while editing your post.

What you intend to do is generally not possible. Several workarounds are possible. For starters, try to look here:

http://www.javaranch.com/journal/200510/Journal200510.jsp#a2
http://www.coderanch.com/t/571069/JDBC/java/PreparedStatements-clause#2596651
 
Esaki muthu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic