This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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: 2501
    
    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
 
Don't get me started about those stupid light bulbs.
 
subject: Ignoring SQL parameters