public class ResultSetWrappingSqlRowSet extends Object implements SqlRowSet
SqlRowSet
interface, wrapping a
ResultSet
, catching any SQLExceptions
and
translating them to a corresponding Spring InvalidResultSetAccessException
.
The passed-in ResultSet should already be disconnected if the SqlRowSet is supposed
to be usable in a disconnected fashion. This means that you will usually pass in a
javax.sql.rowset.CachedRowSet
, which implements the ResultSet interface.
Note: Since JDBC 4.0, it has been clarified that any methods using a String to identify
the column should be using the column label. The column label is assigned using the ALIAS
keyword in the SQL query string. When the query doesn't use an ALIAS, the default label is
the column name. Most JDBC ResultSet implementations follow this new pattern but there are
exceptions such as the com.sun.rowset.CachedRowSetImpl
class which only uses
the column name, ignoring any column labels. As of Spring 3.0.5, ResultSetWrappingSqlRowSet
will translate column labels to the correct column index to provide better support for the
com.sun.rowset.CachedRowSetImpl
which is the default implementation used by
JdbcTemplate
when working with RowSets.
Note: This class implements the java.io.Serializable
marker interface
through the SqlRowSet interface, but is only actually serializable if the disconnected
ResultSet/RowSet contained in it is serializable. Most CachedRowSet implementations
are actually serializable, so this should usually work out.
ResultSet
,
CachedRowSet
,
JdbcTemplate.queryForRowSet(java.lang.String)
,
Serialized FormConstructor and Description |
---|
ResultSetWrappingSqlRowSet(ResultSet resultSet)
Create a new ResultSetWrappingSqlRowSet for the given ResultSet.
|
Modifier and Type | Method and Description |
---|---|
boolean |
absolute(int row)
Move the cursor to the given row number in the row set, just after the last row.
|
void |
afterLast()
Move the cursor to the end of this row set.
|
void |
beforeFirst()
Move the cursor to the front of this row set, just before the first row.
|
int |
findColumn(String columnLabel)
Map the given column label to its column index.
|
boolean |
first()
Move the cursor to the first row of this row set.
|
BigDecimal |
getBigDecimal(int columnIndex)
Retrieve the value of the indicated column in the current row as a BigDecimal object.
|
BigDecimal |
getBigDecimal(String columnLabel)
Retrieve the value of the indicated column in the current row as a BigDecimal object.
|
boolean |
getBoolean(int columnIndex)
Retrieve the value of the indicated column in the current row as a boolean.
|
boolean |
getBoolean(String columnLabel)
Retrieve the value of the indicated column in the current row as a boolean.
|
byte |
getByte(int columnIndex)
Retrieve the value of the indicated column in the current row as a byte.
|
byte |
getByte(String columnLabel)
Retrieve the value of the indicated column in the current row as a byte.
|
Date |
getDate(int columnIndex)
Retrieve the value of the indicated column in the current row as a Date object.
|
Date |
getDate(int columnIndex,
Calendar cal)
Retrieve the value of the indicated column in the current row as a Date object.
|
Date |
getDate(String columnLabel)
Retrieve the value of the indicated column in the current row as a Date object.
|
Date |
getDate(String columnLabel,
Calendar cal)
Retrieve the value of the indicated column in the current row as a Date object.
|
double |
getDouble(int columnIndex)
Retrieve the value of the indicated column in the current row as a Double object.
|
double |
getDouble(String columnLabel)
Retrieve the value of the indicated column in the current row as a Double object.
|
float |
getFloat(int columnIndex)
Retrieve the value of the indicated column in the current row as a float.
|
float |
getFloat(String columnLabel)
Retrieve the value of the indicated column in the current row as a float.
|
int |
getInt(int columnIndex)
Retrieve the value of the indicated column in the current row as an int.
|
int |
getInt(String columnLabel)
Retrieve the value of the indicated column in the current row as an int.
|
long |
getLong(int columnIndex)
Retrieve the value of the indicated column in the current row as a long.
|
long |
getLong(String columnLabel)
Retrieve the value of the indicated column in the current row as a long.
|
SqlRowSetMetaData |
getMetaData()
Retrieve the meta-data, i.e.
|
String |
getNString(int columnIndex)
Retrieve the value of the indicated column in the current row as a String
(for NCHAR, NVARCHAR, LONGNVARCHAR columns).
|
String |
getNString(String columnLabel)
Retrieve the value of the indicated column in the current row as a String
(for NCHAR, NVARCHAR, LONGNVARCHAR columns).
|
Object |
getObject(int columnIndex)
Retrieve the value of the indicated column in the current row as an Object.
|
<T> T |
getObject(int columnIndex,
Class<T> type)
Retrieve the value of the indicated column in the current row as an Object.
|
Object |
getObject(int columnIndex,
Map<String,Class<?>> map)
Retrieve the value of the indicated column in the current row as an Object.
|
Object |
getObject(String columnLabel)
Retrieve the value of the indicated column in the current row as an Object.
|
<T> T |
getObject(String columnLabel,
Class<T> type)
Retrieve the value of the indicated column in the current row as an Object.
|
Object |
getObject(String columnLabel,
Map<String,Class<?>> map)
Retrieve the value of the indicated column in the current row as an Object.
|
ResultSet |
getResultSet()
Return the underlying ResultSet
(usually a
javax.sql.rowset.CachedRowSet ). |
int |
getRow()
Retrieve the current row number.
|
short |
getShort(int columnIndex)
Retrieve the value of the indicated column in the current row as a short.
|
short |
getShort(String columnLabel)
Retrieve the value of the indicated column in the current row as a short.
|
String |
getString(int columnIndex)
Retrieve the value of the indicated column in the current row as a String.
|
String |
getString(String columnLabel)
Retrieve the value of the indicated column in the current row as a String.
|
Time |
getTime(int columnIndex)
Retrieve the value of the indicated column in the current row as a Time object.
|
Time |
getTime(int columnIndex,
Calendar cal)
Retrieve the value of the indicated column in the current row as a Time object.
|
Time |
getTime(String columnLabel)
Retrieve the value of the indicated column in the current row as a Time object.
|
Time |
getTime(String columnLabel,
Calendar cal)
Retrieve the value of the indicated column in the current row as a Time object.
|
Timestamp |
getTimestamp(int columnIndex)
Retrieve the value of the indicated column in the current row as a Timestamp object.
|
Timestamp |
getTimestamp(int columnIndex,
Calendar cal)
Retrieve the value of the indicated column in the current row as a Timestamp object.
|
Timestamp |
getTimestamp(String columnLabel)
Retrieve the value of the indicated column in the current row as a Timestamp object.
|
Timestamp |
getTimestamp(String columnLabel,
Calendar cal)
Retrieve the value of the indicated column in the current row as a Timestamp object.
|
boolean |
isAfterLast()
Retrieve whether the cursor is after the last row of this row set.
|
boolean |
isBeforeFirst()
Retrieve whether the cursor is before the first row of this row set.
|
boolean |
isFirst()
Retrieve whether the cursor is on the first row of this row set.
|
boolean |
isLast()
Retrieve whether the cursor is on the last row of this row set.
|
boolean |
last()
Move the cursor to the last row of this row set.
|
boolean |
next()
Move the cursor to the next row.
|
boolean |
previous()
Move the cursor to the previous row.
|
boolean |
relative(int rows)
Move the cursor a relative number of rows, either positive or negative.
|
boolean |
wasNull()
Report whether the last column read had a value of SQL
NULL . |
public ResultSetWrappingSqlRowSet(ResultSet resultSet) throws InvalidResultSetAccessException
resultSet
- a disconnected ResultSet to wrap
(usually a javax.sql.rowset.CachedRowSet
)InvalidResultSetAccessException
- if extracting
the ResultSetMetaData failedCachedRowSet
,
ResultSet.getMetaData()
,
ResultSetWrappingSqlRowSetMetaData
public final ResultSet getResultSet()
javax.sql.rowset.CachedRowSet
).CachedRowSet
public final SqlRowSetMetaData getMetaData()
SqlRowSet
getMetaData
in interface SqlRowSet
ResultSetMetaData.getCatalogName(int)
public int findColumn(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
findColumn
in interface SqlRowSet
columnLabel
- the name of the columnInvalidResultSetAccessException
ResultSet.findColumn(String)
@Nullable public BigDecimal getBigDecimal(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getBigDecimal
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getBigDecimal(int)
@Nullable public BigDecimal getBigDecimal(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getBigDecimal
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getBigDecimal(String)
public boolean getBoolean(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getBoolean
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getBoolean(int)
public boolean getBoolean(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getBoolean
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getBoolean(String)
public byte getByte(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getByte
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getByte(int)
public byte getByte(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getByte
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getByte(String)
@Nullable public Date getDate(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getDate
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getDate(int)
@Nullable public Date getDate(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getDate
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getDate(String)
@Nullable public Date getDate(int columnIndex, Calendar cal) throws InvalidResultSetAccessException
SqlRowSet
getDate
in interface SqlRowSet
columnIndex
- the column indexcal
- the Calendar to use in constructing the DateInvalidResultSetAccessException
ResultSet.getDate(int, Calendar)
@Nullable public Date getDate(String columnLabel, Calendar cal) throws InvalidResultSetAccessException
SqlRowSet
getDate
in interface SqlRowSet
columnLabel
- the column labelcal
- the Calendar to use in constructing the DateInvalidResultSetAccessException
ResultSet.getDate(String, Calendar)
public double getDouble(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getDouble
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getDouble(int)
public double getDouble(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getDouble
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getDouble(String)
public float getFloat(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getFloat
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getFloat(int)
public float getFloat(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getFloat
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getFloat(String)
public int getInt(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getInt
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getInt(int)
public int getInt(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getInt
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getInt(String)
public long getLong(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getLong
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getLong(int)
public long getLong(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getLong
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getLong(String)
@Nullable public String getNString(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getNString
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getNString(int)
@Nullable public String getNString(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getNString
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getNString(String)
@Nullable public Object getObject(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getObject
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getObject(int)
@Nullable public Object getObject(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getObject
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getObject(String)
@Nullable public Object getObject(int columnIndex, Map<String,Class<?>> map) throws InvalidResultSetAccessException
SqlRowSet
getObject
in interface SqlRowSet
columnIndex
- the column indexmap
- a Map object containing the mapping from SQL types to Java typesInvalidResultSetAccessException
ResultSet.getObject(int, Map)
@Nullable public Object getObject(String columnLabel, Map<String,Class<?>> map) throws InvalidResultSetAccessException
SqlRowSet
getObject
in interface SqlRowSet
columnLabel
- the column labelmap
- a Map object containing the mapping from SQL types to Java typesInvalidResultSetAccessException
ResultSet.getObject(String, Map)
@Nullable public <T> T getObject(int columnIndex, Class<T> type) throws InvalidResultSetAccessException
SqlRowSet
getObject
in interface SqlRowSet
columnIndex
- the column indextype
- the Java type to convert the designated column toInvalidResultSetAccessException
ResultSet.getObject(int, Class)
@Nullable public <T> T getObject(String columnLabel, Class<T> type) throws InvalidResultSetAccessException
SqlRowSet
getObject
in interface SqlRowSet
columnLabel
- the column labeltype
- the Java type to convert the designated column toInvalidResultSetAccessException
ResultSet.getObject(String, Class)
public short getShort(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getShort
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getShort(int)
public short getShort(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getShort
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getShort(String)
@Nullable public String getString(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getString
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getString(int)
@Nullable public String getString(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getString
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getString(String)
@Nullable public Time getTime(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getTime
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getTime(int)
@Nullable public Time getTime(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getTime
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getTime(String)
@Nullable public Time getTime(int columnIndex, Calendar cal) throws InvalidResultSetAccessException
SqlRowSet
getTime
in interface SqlRowSet
columnIndex
- the column indexcal
- the Calendar to use in constructing the DateInvalidResultSetAccessException
ResultSet.getTime(int, Calendar)
@Nullable public Time getTime(String columnLabel, Calendar cal) throws InvalidResultSetAccessException
SqlRowSet
getTime
in interface SqlRowSet
columnLabel
- the column labelcal
- the Calendar to use in constructing the DateInvalidResultSetAccessException
ResultSet.getTime(String, Calendar)
@Nullable public Timestamp getTimestamp(int columnIndex) throws InvalidResultSetAccessException
SqlRowSet
getTimestamp
in interface SqlRowSet
columnIndex
- the column indexInvalidResultSetAccessException
ResultSet.getTimestamp(int)
@Nullable public Timestamp getTimestamp(String columnLabel) throws InvalidResultSetAccessException
SqlRowSet
getTimestamp
in interface SqlRowSet
columnLabel
- the column labelInvalidResultSetAccessException
ResultSet.getTimestamp(String)
@Nullable public Timestamp getTimestamp(int columnIndex, Calendar cal) throws InvalidResultSetAccessException
SqlRowSet
getTimestamp
in interface SqlRowSet
columnIndex
- the column indexcal
- the Calendar to use in constructing the DateInvalidResultSetAccessException
ResultSet.getTimestamp(int, Calendar)
@Nullable public Timestamp getTimestamp(String columnLabel, Calendar cal) throws InvalidResultSetAccessException
SqlRowSet
getTimestamp
in interface SqlRowSet
columnLabel
- the column labelcal
- the Calendar to use in constructing the DateInvalidResultSetAccessException
ResultSet.getTimestamp(String, Calendar)
public boolean absolute(int row) throws InvalidResultSetAccessException
SqlRowSet
absolute
in interface SqlRowSet
row
- the number of the row where the cursor should movetrue
if the cursor is on the row set, false
otherwiseInvalidResultSetAccessException
ResultSet.absolute(int)
public void afterLast() throws InvalidResultSetAccessException
SqlRowSet
afterLast
in interface SqlRowSet
InvalidResultSetAccessException
ResultSet.afterLast()
public void beforeFirst() throws InvalidResultSetAccessException
SqlRowSet
beforeFirst
in interface SqlRowSet
InvalidResultSetAccessException
ResultSet.beforeFirst()
public boolean first() throws InvalidResultSetAccessException
SqlRowSet
first
in interface SqlRowSet
true
if the cursor is on a valid row, false
otherwiseInvalidResultSetAccessException
ResultSet.first()
public int getRow() throws InvalidResultSetAccessException
SqlRowSet
getRow
in interface SqlRowSet
InvalidResultSetAccessException
ResultSet.getRow()
public boolean isAfterLast() throws InvalidResultSetAccessException
SqlRowSet
isAfterLast
in interface SqlRowSet
true
if the cursor is after the last row, false
otherwiseInvalidResultSetAccessException
ResultSet.isAfterLast()
public boolean isBeforeFirst() throws InvalidResultSetAccessException
SqlRowSet
isBeforeFirst
in interface SqlRowSet
true
if the cursor is before the first row, false
otherwiseInvalidResultSetAccessException
ResultSet.isBeforeFirst()
public boolean isFirst() throws InvalidResultSetAccessException
SqlRowSet
isFirst
in interface SqlRowSet
true
if the cursor is after the first row, false
otherwiseInvalidResultSetAccessException
ResultSet.isFirst()
public boolean isLast() throws InvalidResultSetAccessException
SqlRowSet
isLast
in interface SqlRowSet
true
if the cursor is after the last row, false
otherwiseInvalidResultSetAccessException
ResultSet.isLast()
public boolean last() throws InvalidResultSetAccessException
SqlRowSet
last
in interface SqlRowSet
true
if the cursor is on a valid row, false
otherwiseInvalidResultSetAccessException
ResultSet.last()
public boolean next() throws InvalidResultSetAccessException
SqlRowSet
next
in interface SqlRowSet
true
if the new row is valid, false
if there are no more rowsInvalidResultSetAccessException
ResultSet.next()
public boolean previous() throws InvalidResultSetAccessException
SqlRowSet
previous
in interface SqlRowSet
true
if the new row is valid, false
if it is off the row setInvalidResultSetAccessException
ResultSet.previous()
public boolean relative(int rows) throws InvalidResultSetAccessException
SqlRowSet
relative
in interface SqlRowSet
true
if the cursor is on a row, false
otherwiseInvalidResultSetAccessException
ResultSet.relative(int)
public boolean wasNull() throws InvalidResultSetAccessException
SqlRowSet
NULL
.
Note that you must first call one of the getter methods and then
call the wasNull()
method.
wasNull
in interface SqlRowSet
true
if the most recent column retrieved was
SQL NULL
, false
otherwiseInvalidResultSetAccessException
ResultSet.wasNull()