In the DAO Layer, I am trying to convert it but I am getting NumberFormatException because the setter expects an int and I am passing a String.
Instead of a switch,
syed yousuf sadat wrote:Hi. I am writing some data from the database to the CSV file. One of the fields in the database is an int and definitely it prints a number on the csv file. I want to somehow translate those number to a text and then show it to csv file. For instance I want to display "Completed" if the field is 7 in the db. Can I do some kind of switch or if else statement to achieve this.
If I "don't get it" then maybe you need clearer requirements.
syed yousuf sadat wrote:In the DAO Layer, I am trying to convert it but I am getting NumberFormatException because the setter expects an int and I am passing a String.
It is not possible to convert a String which does not represent a numeric value to an Integer or int.
Shouldn't you be using the Integer constant rather than the String constant?
syed yousuf sadat wrote:
This gives me. I know that I am getting an int from the db but I am converting it then why?
Well, the parseInt() method requires a string that can be converted to an int. The word "created" can't be converted back to an int by parsing. If you need to convert it back to the original value, you will need to that yourself as well.
You tell me how could you change the number to a text and display it in a csv file. I am using Apache commons CSV API.
syed yousuf sadat wrote:The reason I am asking this is because I cannot change the model of the project. Status is being defined as int and I cannot change it. This status is coming from the db and in the UI I need to change it to a text.
If your database isn't changed, and the model that the database feeds can't be changed, then why are you trying to change code between the database and the model? Isn't it obvious that this isn't the place to do it?
You need to change the code from the last point (which isn't changed) to the point where you need it changed. This is either between the model and the GUI that needs the change, or the model and the CSV file that you need generated.