• Post Reply Bookmark Topic Watch Topic
  • New Topic

Fixed Condition With PreparedStatament - Use Placeholder?

 
James Gordon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21973
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!