spring-framework / org.springframework.jdbc.support / JdbcUtils / getResultSetValue

getResultSetValue

@Nullable open static fun getResultSetValue(rs: ResultSet, index: Int, @Nullable requiredType: Class<*>): Any

Retrieve a JDBC column value from a ResultSet, using the specified value type.

Uses the specifically typed ResultSet accessor methods, falling back to #getResultSetValue(java.sql.ResultSet, int) for unknown types.

Note that the returned value may not be assignable to the specified required type, in case of an unknown type. Calling code needs to deal with this case appropriately, e.g. throwing a corresponding exception.

Parameters

rs - is the ResultSet holding the data

index - is the column index

requiredType - the required value type (may be null)

Exceptions

SQLException - if thrown by the JDBC API

Return
the value object (possibly not of the specified required type, with further conversion steps necessary)

See Also
#getResultSetValue(ResultSet, int)

@Nullable open static fun getResultSetValue(rs: ResultSet, index: Int): Any

Retrieve a JDBC column value from a ResultSet, using the most appropriate value type. The returned value should be a detached value object, not having any ties to the active ResultSet: in particular, it should not be a Blob or Clob object but rather a byte array or String representation, respectively.

Uses the getObject(index) method, but includes additional "hacks" to get around Oracle 10g returning a non-standard object for its TIMESTAMP datatype and a java.sql.Date for DATE columns leaving out the time portion: These columns will explicitly be extracted as standard java.sql.Timestamp object.

Parameters

rs - is the ResultSet holding the data

index - is the column index

Exceptions

SQLException - if thrown by the JDBC API

Return
the value object

See Also
java.sql.Blobjava.sql.Clobjava.sql.Timestamp