/** * Returns the column value as a {@link Date} with the given {@link Calendar}. * * @param columnIndex 1-based column number (0 is invalid) */ public Date getDate(int columnIndex, Calendar cal) throws SQLException { ByteString rawValue = getRawValue(columnIndex); if (rawValue == null) { return null; } Field field = fieldMap.get(columnIndex); if (field.getType() != Type.DATE) { throw new SQLDataException( "type mismatch, expected: " + Type.DATE + ", actual: " + field.getType()); } try { return DateTime.parseDate(rawValue.toStringUtf8(), cal); } catch (ParseException e) { throw new SQLDataException("Can't parse DATE: " + rawValue.toStringUtf8(), e); } }
/** * Returns the column value as {@link Time} with the given {@link Calendar}. * * @param columnIndex 1-based column number (0 is invalid) */ public Time getTime(int columnIndex, Calendar cal) throws SQLException { ByteString rawValue = getRawValue(columnIndex); if (rawValue == null) { return null; } Field field = fieldMap.get(columnIndex); if (field.getType() != Type.TIME) { throw new SQLDataException( "type mismatch, expected: " + Type.TIME + ", actual: " + field.getType()); } try { return DateTime.parseTime(rawValue.toStringUtf8(), cal); } catch (ParseException e) { throw new SQLDataException("Can't parse TIME: " + rawValue.toStringUtf8(), e); } }
/** * Returns the column value as {@link Timestamp} with the given {@link Calendar}. * * @param columnIndex 1-based column number (0 is invalid) */ public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { ByteString rawValue = getRawValue(columnIndex); if (rawValue == null) { return null; } Field field = fieldMap.get(columnIndex); if (field.getType() != Type.TIMESTAMP && field.getType() != Type.DATETIME) { throw new SQLDataException("type mismatch, expected: " + Type.TIMESTAMP + " or " + Type.DATETIME + ", actual: " + field.getType()); } try { return DateTime.parseTimestamp(rawValue.toStringUtf8(), cal); } catch (ParseException e) { throw new SQLDataException("Can't parse TIMESTAMP: " + rawValue.toStringUtf8(), e); } }