Class SqlNullCheckedResultSet
java.lang.Object
org.apache.commons.dbutils.wrappers.SqlNullCheckedResultSet
- All Implemented Interfaces:
InvocationHandler
Decorates a
ResultSet with checks for a SQL NULL value on each
getXXX method. If a column value obtained by a
getXXX method is not SQL NULL, the column value is returned. If
the column value is SQL null, an alternate value is returned. The alternate
value defaults to the Java null value, which can be overridden
for instances of the class.
Usage example:
Connection conn = // somehow get a connection
Statement stmt = conn.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT col1, col2 FROM table1");
// Wrap the result set for SQL NULL checking
SqlNullCheckedResultSet wrapper = new SqlNullCheckedResultSet(resultSet);
wrapper.setNullString("---N/A---"); // Set null string
wrapper.setNullInt(-999); // Set null integer
resultSet = ProxyFactory.instance().createResultSet(wrapper);
while (resultSet.next()) {
// If col1 is SQL NULL, value returned will be "---N/A---"
String col1 = resultSet.getString("col1");
// If col2 is SQL NULL, value returned will be -999
int col2 = resultSet.getInt("col2");
}
resultSet.close();
</p>
Unlike some other classes in DbUtils, this class is NOT thread-safe.
-
Constructor Summary
ConstructorsConstructorDescriptionSqlNullCheckedResultSet(ResultSet resultSet) Constructs a new instance ofSqlNullCheckedResultSetto wrap the specifiedResultSet. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value when a SQL null is encountered as the result of invoking agetAsciiStreammethod.Returns the value when a SQL null is encountered as the result of invoking agetBigDecimalmethod.Returns the value when a SQL null is encountered as the result of invoking agetBinaryStreammethod.Returns the value when a SQL null is encountered as the result of invoking agetBlobmethod.booleanReturns the value when a SQL null is encountered as the result of invoking agetBooleanmethod.byteReturns the value when a SQL null is encountered as the result of invoking agetBytemethod.byte[]Returns the value when a SQL null is encountered as the result of invoking agetBytesmethod.Returns the value when a SQL null is encountered as the result of invoking agetCharacterStreammethod.Returns the value when a SQL null is encountered as the result of invoking agetClobmethod.Returns the value when a SQL null is encountered as the result of invoking agetDatemethod.doubleReturns the value when a SQL null is encountered as the result of invoking agetDoublemethod.floatReturns the value when a SQL null is encountered as the result of invoking agetFloatmethod.intReturns the value when a SQL null is encountered as the result of invoking agetIntmethod.longReturns the value when a SQL null is encountered as the result of invoking agetLongmethod.Returns the value when a SQL null is encountered as the result of invoking agetObjectmethod.Returns the value when a SQL null is encountered as the result of invoking agetRefmethod.shortReturns the value when a SQL null is encountered as the result of invoking agetShortmethod.Returns the value when a SQL null is encountered as the result of invoking agetStringmethod.Returns the value when a SQL null is encountered as the result of invoking agetTimemethod.Returns the value when a SQL null is encountered as the result of invoking agetTimestampmethod.Returns the value when a SQL null is encountered as the result of invoking agetURLmethod.Intercepts calls toget*methods and calls the appropriategetNull*method if theResultSetreturnednull.voidsetNullAsciiStream(InputStream nullAsciiStream) Sets the value to return when a SQL null is encountered as the result of invoking agetAsciiStreammethod.voidsetNullBigDecimal(BigDecimal nullBigDecimal) Sets the value to return when a SQL null is encountered as the result of invoking agetBigDecimalmethod.voidsetNullBinaryStream(InputStream nullBinaryStream) Sets the value to return when a SQL null is encountered as the result of invoking agetBinaryStreammethod.voidsetNullBlob(Blob nullBlob) Sets the value to return when a SQL null is encountered as the result of invoking agetBlobmethod.voidsetNullBoolean(boolean nullBoolean) Sets the value to return when a SQL null is encountered as the result of invoking agetBooleanmethod.voidsetNullByte(byte nullByte) Sets the value to return when a SQL null is encountered as the result of invoking agetBytemethod.voidsetNullBytes(byte[] nullBytes) Sets the value to return when a SQL null is encountered as the result of invoking agetBytesmethod.voidsetNullCharacterStream(Reader nullCharacterStream) Sets the value to return when a SQL null is encountered as the result of invoking agetCharacterStreammethod.voidsetNullClob(Clob nullClob) Sets the value to return when a SQL null is encountered as the result of invoking agetClobmethod.voidsetNullDate(Date nullDate) Sets the value to return when a SQL null is encountered as the result of invoking agetDatemethod.voidsetNullDouble(double nullDouble) Sets the value to return when a SQL null is encountered as the result of invoking agetDoublemethod.voidsetNullFloat(float nullFloat) Sets the value to return when a SQL null is encountered as the result of invoking agetFloatmethod.voidsetNullInt(int nullInt) Sets the value to return when a SQL null is encountered as the result of invoking agetIntmethod.voidsetNullLong(long nullLong) Sets the value to return when a SQL null is encountered as the result of invoking agetLongmethod.voidsetNullObject(Object nullObject) Sets the value to return when a SQL null is encountered as the result of invoking agetObjectmethod.voidsetNullRef(Ref nullRef) Sets the value to return when a SQL null is encountered as the result of invoking agetRefmethod.voidsetNullShort(short nullShort) Sets the value to return when a SQL null is encountered as the result of invoking agetShortmethod.voidsetNullString(String nullString) Sets the value to return when a SQL null is encountered as the result of invoking agetStringmethod.voidsetNullTime(Time nullTime) Sets the value to return when a SQL null is encountered as the result of invoking agetTimemethod.voidsetNullTimestamp(Timestamp nullTimestamp) Sets the value to return when a SQL null is encountered as the result of invoking agetTimestampmethod.voidsetNullURL(URL nullURL) Sets the value to return when a SQL null is encountered as the result of invoking agetURLmethod.static ResultSetWraps theResultSetin an instance of this class.
-
Constructor Details
-
SqlNullCheckedResultSet
Constructs a new instance ofSqlNullCheckedResultSetto wrap the specifiedResultSet.- Parameters:
resultSet- ResultSet to wrap
-
-
Method Details
-
wrap
Wraps theResultSetin an instance of this class. This is equivalent to:ProxyFactory.instance().createResultSet(new SqlNullCheckedResultSet(resultSet));
- Parameters:
resultSet- TheResultSetto wrap.- Returns:
- wrapped ResultSet
-
getNullAsciiStream
Returns the value when a SQL null is encountered as the result of invoking agetAsciiStreammethod.- Returns:
- the value
-
getNullBigDecimal
Returns the value when a SQL null is encountered as the result of invoking agetBigDecimalmethod.- Returns:
- the value
-
getNullBinaryStream
Returns the value when a SQL null is encountered as the result of invoking agetBinaryStreammethod.- Returns:
- the value
-
getNullBlob
Returns the value when a SQL null is encountered as the result of invoking agetBlobmethod.- Returns:
- the value
-
getNullBoolean
Returns the value when a SQL null is encountered as the result of invoking agetBooleanmethod.- Returns:
- the value
-
getNullByte
Returns the value when a SQL null is encountered as the result of invoking agetBytemethod.- Returns:
- the value
-
getNullBytes
Returns the value when a SQL null is encountered as the result of invoking agetBytesmethod.- Returns:
- the value
-
getNullCharacterStream
Returns the value when a SQL null is encountered as the result of invoking agetCharacterStreammethod.- Returns:
- the value
-
getNullClob
Returns the value when a SQL null is encountered as the result of invoking agetClobmethod.- Returns:
- the value
-
getNullDate
Returns the value when a SQL null is encountered as the result of invoking agetDatemethod.- Returns:
- the value
-
getNullDouble
Returns the value when a SQL null is encountered as the result of invoking agetDoublemethod.- Returns:
- the value
-
getNullFloat
Returns the value when a SQL null is encountered as the result of invoking agetFloatmethod.- Returns:
- the value
-
getNullInt
Returns the value when a SQL null is encountered as the result of invoking agetIntmethod.- Returns:
- the value
-
getNullLong
Returns the value when a SQL null is encountered as the result of invoking agetLongmethod.- Returns:
- the value
-
getNullObject
Returns the value when a SQL null is encountered as the result of invoking agetObjectmethod.- Returns:
- the value
-
getNullRef
Returns the value when a SQL null is encountered as the result of invoking agetRefmethod.- Returns:
- the value
-
getNullShort
Returns the value when a SQL null is encountered as the result of invoking agetShortmethod.- Returns:
- the value
-
getNullString
Returns the value when a SQL null is encountered as the result of invoking agetStringmethod.- Returns:
- the value
-
getNullTime
Returns the value when a SQL null is encountered as the result of invoking agetTimemethod.- Returns:
- the value
-
getNullTimestamp
Returns the value when a SQL null is encountered as the result of invoking agetTimestampmethod.- Returns:
- the value
-
getNullURL
Returns the value when a SQL null is encountered as the result of invoking agetURLmethod.- Returns:
- the value
-
invoke
Intercepts calls toget*methods and calls the appropriategetNull*method if theResultSetreturnednull.- Specified by:
invokein interfaceInvocationHandler- Parameters:
proxy- Not used; all method calls go to the internal result setmethod- The method to invoke on the result setargs- The arguments to pass to the result set- Returns:
- null checked result
- Throws:
Throwable- error- See Also:
-
setNullAsciiStream
Sets the value to return when a SQL null is encountered as the result of invoking agetAsciiStreammethod.- Parameters:
nullAsciiStream- the value
-
setNullBigDecimal
Sets the value to return when a SQL null is encountered as the result of invoking agetBigDecimalmethod.- Parameters:
nullBigDecimal- the value
-
setNullBinaryStream
Sets the value to return when a SQL null is encountered as the result of invoking agetBinaryStreammethod.- Parameters:
nullBinaryStream- the value
-
setNullBlob
Sets the value to return when a SQL null is encountered as the result of invoking agetBlobmethod.- Parameters:
nullBlob- the value
-
setNullBoolean
Sets the value to return when a SQL null is encountered as the result of invoking agetBooleanmethod.- Parameters:
nullBoolean- the value
-
setNullByte
Sets the value to return when a SQL null is encountered as the result of invoking agetBytemethod.- Parameters:
nullByte- the value
-
setNullBytes
Sets the value to return when a SQL null is encountered as the result of invoking agetBytesmethod.- Parameters:
nullBytes- the value
-
setNullCharacterStream
Sets the value to return when a SQL null is encountered as the result of invoking agetCharacterStreammethod.- Parameters:
nullCharacterStream- the value
-
setNullClob
Sets the value to return when a SQL null is encountered as the result of invoking agetClobmethod.- Parameters:
nullClob- the value
-
setNullDate
Sets the value to return when a SQL null is encountered as the result of invoking agetDatemethod.- Parameters:
nullDate- the value
-
setNullDouble
Sets the value to return when a SQL null is encountered as the result of invoking agetDoublemethod.- Parameters:
nullDouble- the value
-
setNullFloat
Sets the value to return when a SQL null is encountered as the result of invoking agetFloatmethod.- Parameters:
nullFloat- the value
-
setNullInt
Sets the value to return when a SQL null is encountered as the result of invoking agetIntmethod.- Parameters:
nullInt- the value
-
setNullLong
Sets the value to return when a SQL null is encountered as the result of invoking agetLongmethod.- Parameters:
nullLong- the value
-
setNullObject
Sets the value to return when a SQL null is encountered as the result of invoking agetObjectmethod.- Parameters:
nullObject- the value
-
setNullRef
Sets the value to return when a SQL null is encountered as the result of invoking agetRefmethod.- Parameters:
nullRef- the value
-
setNullShort
Sets the value to return when a SQL null is encountered as the result of invoking agetShortmethod.- Parameters:
nullShort- the value
-
setNullString
Sets the value to return when a SQL null is encountered as the result of invoking agetStringmethod.- Parameters:
nullString- the value
-
setNullTime
Sets the value to return when a SQL null is encountered as the result of invoking agetTimemethod.- Parameters:
nullTime- the value
-
setNullTimestamp
Sets the value to return when a SQL null is encountered as the result of invoking agetTimestampmethod.- Parameters:
nullTimestamp- the value
-
setNullURL
Sets the value to return when a SQL null is encountered as the result of invoking agetURLmethod.- Parameters:
nullURL- the value
-