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 Fixed Condition With PreparedStatament - Use Placeholder? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "Fixed Condition With PreparedStatament - Use Placeholder?" Watch "Fixed Condition With PreparedStatament - Use Placeholder?" New topic
Author

Fixed Condition With PreparedStatament - Use Placeholder?

James Gordon
Ranch Hand

Joined: Aug 09, 2002
Posts: 106
Hi,

Let's say I have a query (PreparedStatement) with some conditions and one of it
is a fixed condition. Below is to illustrate:



Take note of field3 which has a fixed condition.
Is it a good idea to make it a placeholder(?) as well?

It's going to achieve the same thing but I'm just looking
for good practice.

Please comment.


Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Not really, no.

Edit: Why do I say that? Because it's not generally a good idea to write code that isn't necessary. Even there's only one more line of code for you to write, it's still a line of code which you might get wrong, and which has to be tested.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

If its really a fixed value, then hard coding is more secure and trouble free than putting one more statement for the same, which finally, yields the same result.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
 
GeeCON Prague 2014
 
subject: Fixed Condition With PreparedStatament - Use Placeholder?