A problem with MapSqlParameterSource
So, here is the scenario:
I have a table with three columns:
- ID, VARCHAR2, NULLABLE = N
- VALUE1, NUMBER, NULLABLE = Y
- VALUE2, NUMBER, NULLABLE = Y
- VALUE3, VARCHAR2, NULLABLE = Y
All data is from String messages which simply concanate all column values by "||", for example:
"id01||01||02||03" or, "id02||||02||||" .
My mission is to split those values for each column, and save them into the database.
I used the named parameters. My code is like this:
Code:
String message = "id01||01||02||03";
String[] paras = message.split("\\|\\|");
SqlParameterSource namedParameters = new MapSqlParameterSource().addValue("ID", paras[0])
.addValue("VALUE1",paras[1], Types.NUMERIC)
.addValue("VALUE2",paras[1], Types.NUMERIC)
.addValue("VALUE2",paras[1], Types.NUMERIC)
This works fine for message like "id01||01||02||03".
But for message like "id02||||02||||", it crashes because of casting null into an integer.
Any ideas to solve this problem elegantly?