File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Fixed Condition With PreparedStatament - Use Placeholder?
Joined: Aug 09, 2002
Mar 19, 2009 20:50:09
Let's say I have a query (
) with some conditions and one of it
is a fixed condition. Below is to illustrate:
SELECT * FROM mytable WHERE field1 = ? AND field2 = ? AND field3 = 0
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.
Thanks in advance.
Joined: Oct 14, 2005
Mar 19, 2009 21:44:58
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.
Joined: Feb 19, 2008
Mar 19, 2009 22:51:52
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.
[Freelance Web Designer]
[and "Rohan" is part of my surname]
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
subject: Fixed Condition With PreparedStatament - Use Placeholder?
why my sql in jsp is error?
overiding equals() method
How to read instance variable dynamically?
PostgreSQL prepared statement failure
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013