Menu

#8 StreamingResultSet.getTimestamp(int, Calendar) NPE & CCE

open
nobody
None
5
2012-05-09
2012-05-09
No

We ran into a couple of issues with de.simplicit.vjdbc.serial.StreamingResultSet.getTimestamp(int, Calendar). When a null calendar is supplied, a NullPointerException occurs. Secondly, when a non-null Calendar is supplied, a ClassCastException occurs since java.util.Date cannot be cast to java.sql.Timestamp. Updating the method as follows solves both of the issues:

public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
Timestamp timestamp = getTimestamp(columnIndex);
if(timestamp != null) {
if (cal != null) {
cal.setTime(timestamp);
return new Timestamp(cal.getTime().getTime());
}
else {
return timestamp;
}
}
else {
return null;
}
}

Discussion


Log in to post a comment.