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 Ignoring SQL parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Ignoring SQL parameters" Watch "Ignoring SQL parameters" New topic
Author

Ignoring SQL parameters

Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
Hello,

I have this statement for example:

SELECT * FROM mytable WHERE col1='val1' AND col2='val2';

one of the parameters could be null and in this case i'd like it ignored. How can i do this without using ifs, since in the code i actually have 7 parameters and it's a hassle to check if every parameter is null;

Thanks
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2495
    
    8

i actually have 7 parameters and it's a hassle to check if every parameter is nul
I'm afraid that you will have to go through the hassle. How would you resolve this without checking it in your code, and dynamically creating the sql statement?


OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ignoring SQL parameters