use of com.mysql.cj.exceptions.DataTruncationException in project aws-mysql-jdbc by awslabs.
the class NativeProtocol method checkErrorMessage.
public void checkErrorMessage(NativePacketPayload resultPacket) {
resultPacket.setPosition(0);
byte statusCode = (byte) resultPacket.readInteger(IntegerDataType.INT1);
// Error handling
if (statusCode == (byte) 0xff) {
String serverErrorMessage;
int errno = 2000;
errno = (int) resultPacket.readInteger(IntegerDataType.INT2);
String xOpen = null;
serverErrorMessage = resultPacket.readString(StringSelfDataType.STRING_TERM, this.serverSession.getCharsetSettings().getErrorMessageEncoding());
if (serverErrorMessage.charAt(0) == '#') {
// we have an SQLState
if (serverErrorMessage.length() > 6) {
xOpen = serverErrorMessage.substring(1, 6);
serverErrorMessage = serverErrorMessage.substring(6);
if (xOpen.equals("HY000")) {
xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
}
} else {
xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
}
} else {
xOpen = MysqlErrorNumbers.mysqlToSqlState(errno);
}
clearInputStream();
StringBuilder errorBuf = new StringBuilder();
String xOpenErrorMessage = MysqlErrorNumbers.get(xOpen);
boolean useOnlyServerErrorMessages = this.propertySet.getBooleanProperty(PropertyKey.useOnlyServerErrorMessages).getValue();
if (!useOnlyServerErrorMessages) {
if (xOpenErrorMessage != null) {
errorBuf.append(xOpenErrorMessage);
errorBuf.append(Messages.getString("Protocol.0"));
}
}
errorBuf.append(serverErrorMessage);
if (!useOnlyServerErrorMessages) {
if (xOpenErrorMessage != null) {
errorBuf.append("\"");
}
}
appendDeadlockStatusInformation(this.session, xOpen, errorBuf);
if (xOpen != null) {
if (xOpen.startsWith("22")) {
throw new DataTruncationException(errorBuf.toString(), 0, true, false, 0, 0, errno);
}
if (errno == MysqlErrorNumbers.ER_MUST_CHANGE_PASSWORD) {
throw ExceptionFactory.createException(PasswordExpiredException.class, errorBuf.toString(), getExceptionInterceptor());
} else if (errno == MysqlErrorNumbers.ER_MUST_CHANGE_PASSWORD_LOGIN) {
throw ExceptionFactory.createException(ClosedOnExpiredPasswordException.class, errorBuf.toString(), getExceptionInterceptor());
} else if (errno == MysqlErrorNumbers.ER_CLIENT_INTERACTION_TIMEOUT) {
throw ExceptionFactory.createException(CJCommunicationsException.class, errorBuf.toString(), null, getExceptionInterceptor());
}
}
throw ExceptionFactory.createException(errorBuf.toString(), xOpen, errno, false, null, getExceptionInterceptor());
}
}
Aggregations