Search in sources :

Example 1 with DataConversionException

use of com.mysql.cj.exceptions.DataConversionException in project aws-mysql-jdbc by awslabs.

the class OffsetDateTimeValueFactory method createFromBytes.

@Override
public OffsetDateTime createFromBytes(byte[] bytes, int offset, int length, Field f) {
    if (length == 0 && this.pset.getBooleanProperty(PropertyKey.emptyStringsConvertToZero).getValue()) {
        return createFromLong(0);
    }
    String s = StringUtils.toString(bytes, offset, length, f.getEncoding());
    byte[] newBytes = s.getBytes();
    if (MysqlTextValueDecoder.isDate(s)) {
        return createFromDate(MysqlTextValueDecoder.getDate(newBytes, 0, newBytes.length));
    } else if (MysqlTextValueDecoder.isTime(s)) {
        return createFromTime(MysqlTextValueDecoder.getTime(newBytes, 0, newBytes.length, f.getDecimals()));
    } else if (MysqlTextValueDecoder.isTimestamp(s)) {
        return createFromTimestamp(MysqlTextValueDecoder.getTimestamp(newBytes, 0, newBytes.length, f.getDecimals()));
    }
    // by default try to parse
    try {
        return OffsetDateTime.parse(s.replace(" ", "T"));
    } catch (DateTimeParseException e) {
        throw new DataConversionException(Messages.getString("ResultSet.UnableToConvertString", new Object[] { s, getTargetTypeName() }));
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) DataConversionException(com.mysql.cj.exceptions.DataConversionException)

Example 2 with DataConversionException

use of com.mysql.cj.exceptions.DataConversionException in project aws-mysql-jdbc by awslabs.

the class ZonedDateTimeValueFactory method createFromBytes.

@Override
public ZonedDateTime createFromBytes(byte[] bytes, int offset, int length, Field f) {
    if (length == 0 && this.pset.getBooleanProperty(PropertyKey.emptyStringsConvertToZero).getValue()) {
        return createFromLong(0);
    }
    String s = StringUtils.toString(bytes, offset, length, f.getEncoding());
    byte[] newBytes = s.getBytes();
    if (MysqlTextValueDecoder.isDate(s)) {
        return createFromDate(MysqlTextValueDecoder.getDate(newBytes, 0, newBytes.length));
    } else if (MysqlTextValueDecoder.isTime(s)) {
        return createFromTime(MysqlTextValueDecoder.getTime(newBytes, 0, newBytes.length, f.getDecimals()));
    } else if (MysqlTextValueDecoder.isTimestamp(s)) {
        return createFromTimestamp(MysqlTextValueDecoder.getTimestamp(newBytes, 0, newBytes.length, f.getDecimals()));
    }
    // by default try to parse
    try {
        return ZonedDateTime.parse(s.replace(" ", "T"));
    } catch (DateTimeParseException e) {
        throw new DataConversionException(Messages.getString("ResultSet.UnableToConvertString", new Object[] { s, getTargetTypeName() }));
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) DataConversionException(com.mysql.cj.exceptions.DataConversionException)

Example 3 with DataConversionException

use of com.mysql.cj.exceptions.DataConversionException in project aws-mysql-jdbc by awslabs.

the class OffsetTimeValueFactory method createFromBytes.

@Override
public OffsetTime createFromBytes(byte[] bytes, int offset, int length, Field f) {
    if (length == 0 && this.pset.getBooleanProperty(PropertyKey.emptyStringsConvertToZero).getValue()) {
        return createFromLong(0);
    }
    String s = StringUtils.toString(bytes, offset, length, f.getEncoding());
    byte[] newBytes = s.getBytes();
    if (MysqlTextValueDecoder.isDate(s)) {
        return createFromDate(MysqlTextValueDecoder.getDate(newBytes, 0, newBytes.length));
    } else if (MysqlTextValueDecoder.isTime(s)) {
        return createFromTime(MysqlTextValueDecoder.getTime(newBytes, 0, newBytes.length, f.getDecimals()));
    } else if (MysqlTextValueDecoder.isTimestamp(s)) {
        return createFromTimestamp(MysqlTextValueDecoder.getTimestamp(newBytes, 0, newBytes.length, f.getDecimals()));
    }
    // by default try to parse
    try {
        return OffsetTime.parse(s);
    } catch (DateTimeParseException e) {
        throw new DataConversionException(Messages.getString("ResultSet.UnableToConvertString", new Object[] { s, getTargetTypeName() }));
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) DataConversionException(com.mysql.cj.exceptions.DataConversionException)

Aggregations

DataConversionException (com.mysql.cj.exceptions.DataConversionException)3 DateTimeParseException (java.time.format.DateTimeParseException)3