Re: [OJB-developers] Detecting and mapping null Integer values
Brought to you by:
thma
From: Florian B. <bf...@fl...> - 2002-02-13 19:37:33
|
Hi, > > If the string value is null getString will return a null > reference. But for > > Integer (and other classes) the following is used: > > > > case Types.INTEGER: > > result = new Integer(rs.getInt(columnId)); > > break; > > > > > > I get your point. But: how should the above code look like to handle > your problem correctly? I have no idea. > If you (or somebody else) tell me how this section should look like I > will change it! > the foolproof solution, although not the quickest one: Integer result = null; case Types.INTEGER: if (rs.getObject(columnId) == null) result = null; else result = new Integer(rs.getInt(columnId); break; the optimized but a lot more dangerous solution would be: case Types.INTEGER: result = rs.getObject(columnId); There is no guarantee the getObject will return an Integer object here, so typechecking and conversion would be deferred to the ConversionStragety object. MfG, Florian Bruckner |