In my database application I sometimes have to deal with null strings in the database. In most cases this is fine, but when it comes do displaying data in a form the Swing components - using JTextField for example - cannot handle null strings. (.setText(null) fails)
(EDIT: I just noticed that JTextField actually accepts a null string, but the question remains for all other cases where unexpected null values can lead to problems.)
The null values have no special meaning, they can (must) be treated as empty strings.
What is the best practice to deal with this problem? Unfortunatly I cannot change the database.
- Checking every value if it is
nullbefore callingsetText()? - Adding a try-catch handler to every
setText()call? - Introducing a static method which filters all
nullstrings? - Replace all
nullvalues to empty strings immediatly after reading from the database? - ... [your suggestions]