File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to use create query with having list as parameter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to use create query with having list as parameter" Watch "How to use create query with having list as parameter" New topic
Author

How to use create query with having list as parameter

Esaki muthu
Greenhorn

Joined: Apr 05, 2012
Posts: 7
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

Joined: Dec 08, 2010
Posts: 1506
    
    5

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.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

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

Joined: Apr 05, 2012
Posts: 7
Thanks ....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to use create query with having list as parameter