This week's book giveaway is in the
We're giving away four copies of
and have Sam Newman on-line!
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
this week in the
JDBC and Relational Databases
Fixed Condition With PreparedStatament - Use Placeholder?
Joined: Aug 09, 2002
Mar 19, 2009 20:50:09
Let's say I have a query (PreparedStatement) 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]
I agree. Here's the link:
subject: Fixed Condition With PreparedStatament - Use Placeholder?
How to read instance variable dynamically?
why my sql in jsp is error?
PostgreSQL prepared statement failure
overiding equals() method
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015