Does JDBC ResultSet getString always return a String representation?

jdbc

Solution

Yup, check this : http://java.sun.com/docs/books/tutorial/jdbc/basics/retrieving.html

JDBC allows a lot of latitude as far as which getXXX methods you can use to retrieve the different SQL types. For example, the method getInt can be used to retrieve any of the numeric or character types. The data it retrieves will be converted to an int; that is, if the SQL type is VARCHAR , JDBC will attempt to parse an integer out of the VARCHAR. The method getInt is recommended for retrieving only SQL INTEGER types, however, and it cannot be used for the SQL types BINARY, VARBINARY, LONGVARBINARY, DATE , TIME, or TIMESTAMP.

But be careful, different JDBC driver may yield different result.

Problem

I'm formatting a `ResultSet` to output to a CSV file. As such I really don't care about the Java types of the result set, beyond maybe knowing if it's text or numbers. Does JDBC guarantee getString will always give a string representation of the values,atleast for single values (I don't need to concern myself about `java.sql.Types.ARRAY`,`java.sql.Types.JAVA_OBJECT` and a few others). e.g. given `resultSetMetaData.getColumnType(i)` is a `Types.FLOAT` or a `Types.BIGDECIMAL`. will `rs.GetString(i)` always yield some String ? i.e. Are there cases getString will throw an SQLException or return null when a getXXX would give me the value ?

Original source