> Oracle, for instance, will typically return a BigDecimal from getObject()
> for just about every numeric column type. One way to get a Short via getObject()
> regardless of the driver is to do this:
>
> Short myShort = (Number)(myResultSet.getObject("myCol")).shortValue();
Why not get the short value directly,
short myShort = myResultSet.getShort("myCol");
and if Carlo really needs an object, he can make one afterwards:
Short myShortObject = new Short(myShort);
David Harper
Cambridge, England
Joe Weinstein - 19 Nov 2004 16:46 GMT
>> Oracle, for instance, will typically return a BigDecimal from getObject()
>> for just about every numeric column type. One way to get a Short via
[quoted text clipped - 13 lines]
> David Harper
> Cambridge, England
Absolutely right, David. And there is one more wrinkle: If the column
allows null values, then getShort() will return a 0 for a null value,
and the OP would have to call wasNull() after that to know whether it
was a real 0 or really a null. And my code would have failed too,
because the getObject() would have returned a null.
Thus, if the user knows they want, they should ask for it, and then
check for null, if needed. If they call getObject(), it'll be obvious,
and if they know that they want/expect a short value, they can always
call wasNull() after it.
Joe
Joe