No wait, I see what you're thinking. Good idea. You're hoping that you can do this:
The problem is that city and state are strings. Your theory is OK except you can't tell the difference between #2 and #3. One of the ways you can handle this is:
Now the trouble here, is how do you define City and State? Here's a possible definition for State:
NOTE: Now is a REALLY GOOD TIME to take a peek at Java 1.5 Enumerated types, which would handle just this sort of problem:
http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html Now you get:
... which would work! Would you encapsulate City into a String? Naw, I don't think that's such a great idea. A City class wouldn't provide any additional knowledge, it's just a way to encapsulate. You're going down a slippery slope here. What if you want to add Zip Code? What about Zip Code, First Name, Last Name, Middle Name, Zip Code Extension, Suffix ("Jr.", "Sr."), Title("Mr.", "Ms.", "Mrs.", "Dr.") and so forth?
Naw, if you want to handle that type of genericity, I'd suggest you do this:
I'll leave it to you to write getSql... but I'll give you a hint by showing how I would use it: