Automatic conversion problem with JDBC
Hello All,
I'm returning a resultset from a db call using:
<code>String value = rs.getString(columnName);<code>
What I'm seeing are values like:
.00031565 and .0003629975 coming back in scientific notation. as in 3.1565E-4 for example. Is this a jdbc thing to automatically convert values being returned like this? What is the best way to resolve this? Keep in mind also that I won't know what the datatype is I'm returning until runtime, so I'm thinking I have to use ResultSetMetaData to query what the column datatype is and then use the correct rs.get(dataType method), but I'm guessing. Also, we are using Sybase 5.2 and jdbc 2.
Any help would be appreciated!
Thanks,
James
# 1
If you retrieve a numeric type as a String you can't be too surprised if it converts between the two types.(edit). Yes, if you don't want automatic conversion you'll have to identify the type and convert it yourself. But why don't you know the datatype?
# 2
The program is an adhoc query and they can make multiple selections for data tables that we can't predict ahead of time, but yes it appears to be as simple as determining the correct datatype at runtime and then using the appropriate get method. I'll try it again today.
# 6
Yep. Because null doesn't have an object type, and because you may not want the default type conversion (JDBC types are not equivalent to Java types, so while the conversion will be sufficient it may not be desirable).