I need to parse the value of a database column that generally contains integers, based on the result Set generated from a JDBC call. However, one particular row of the column has two integers in it (ie, "48, 103"). What will be the return value of resultSet.getInt() on that column?
It will throw an exception.
I think you are taking the wrong approach here. The getXXX()
is supposed to match the data type of the table. Is the data type on the table listed as VARCHAR? If that case you should use getString() to get the data and then parse it with the String.spilt(",") if the ,
exists (you can use String.indexOf() to verify is the comma is there or not).
You'll almost certainly get a SQLException
(or possibly a NumberFormatException
). The actual interface just says that the result set will return "the value of the designated column... as an int
". The exact details will be implementation-specific, but I doubt you'll get anything sensible from a value of "48, 103"
.
(Personally I think it's an error if the driver lets you call getInt
on that column in any case, even for "sensible" values. A string is not an int, even if it's a string representation of an int, and the conversion should be done manually by the developer.)
I'd expect it to throw an exception. If it does give you a value, it won't be what you want. I'd get the values as strings and parse them, splitting on commas and trimming spaces.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With