Database was set up prior to me coming on board. If the data exists, it is loaded into the database table otherwise it is left off. No flags. For example, we have a users table and we have a cars table. If a user has a car, then the user_id is on the car table. If a user does not have a car, the user_id is not on the car table.
I have to return whether or not a user has a car. If they have a car, I need to return 'Car', otherwise 'No Car'. I cannot change the tables. Any suggestions?
Steve, A resultset can never be null. If there aren't any results, you will get a resultset object whose next() method returns false on the first call.
Joined: Jul 03, 2003
Thanks! Ahhhhh what was I thinking? :roll:
My new approach is to write an isCar() and setCar().
Then I can do something like (foo.isCar()?"Car":"No Car")
This way I can go through my collection of Users and determine if they have a car or not. Implementing this is taking me a bit though. I haven't figured it out. How do I put this in? Any pointers would be helpful. Thanks
Steve, I just re-read the initial post and want to clarify what I just posted. While you can't change the database, you can still have your java object store a boolean if you want. You can even have an isCar() method that returns the boolean and a getCar() method that returns 'Car' or 'No Car'. That way the logic is more centralized. But that's more refactoring than your actual question.
For the query, you can do something like this:
This query will return a result set with one row and one column. That entry is zero if the answer is no car and more than zero if the answer is car.