开发者

Read from a delimited input file and populate a table

I have to read from a ^ delimited file and then pulate a table. Table has nullable integer columns. When there is no value specified in the input file, the c开发者_运维问答olumn should be made to null.

I need to process the input data first and then insert into the table. So I am reading them into a valueObject with integer data elements. But if I then try to create table rows from the valueObject, integers get converted into 0 values.

How do I avoid this?

Thanks


I think you have 2 possible ways:

1/ If you use primitive int: you can use a special code, for example, you can use -1 (in case all other values are positive), you can use Integer.MAX_INTEGER or Integer.MIN_INTEGER. Then, when you put data into the database, you can check for this special code, if the value is equal to the special code, you put the null instead.

2/ You can use an Integer object, then, if you see no value in file, you you point that object to null. Then when you write to database, it should just work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜