JDBC Type 4 driver for MySQL with X DevAPI support for document store operations
Comprehensive exception hierarchy for handling errors and exceptional conditions throughout the driver. All connector exceptions are unchecked (runtime exceptions) at the core level, with JDBC-specific SQLException wrappers where required.
Core exception class that all connector exceptions extend.
package com.mysql.cj.exceptions;
public class CJException extends RuntimeException {
public CJException();
public CJException(String message);
public CJException(Throwable cause);
public CJException(String message, Throwable cause);
}Exceptions related to network communication failures.
package com.mysql.cj.exceptions;
public class CJCommunicationsException extends CJException {
public CJCommunicationsException(String message);
public CJCommunicationsException(String message, Throwable cause);
}
public class UnableToConnectException extends CJException {
public UnableToConnectException(String message);
public UnableToConnectException(String message, Throwable cause);
}
package com.mysql.cj.jdbc.exceptions;
public class CommunicationsException extends java.sql.SQLException {
public CommunicationsException(String message, Throwable underlyingException);
}Exceptions for timeouts and cancelled operations.
package com.mysql.cj.exceptions;
public class CJTimeoutException extends CJException {
public CJTimeoutException(String message);
}
public class OperationCancelledException extends CJException {
public OperationCancelledException(String message);
}
package com.mysql.cj.jdbc.exceptions;
public class MySQLTimeoutException extends java.sql.SQLException {
public MySQLTimeoutException();
public MySQLTimeoutException(String message);
}
public class MySQLStatementCancelledException extends java.sql.SQLException {
public MySQLStatementCancelledException();
public MySQLStatementCancelledException(String message);
}
public class MySQLQueryInterruptedException extends java.sql.SQLException {
public MySQLQueryInterruptedException();
}Exceptions related to transaction failures.
package com.mysql.cj.jdbc.exceptions;
public class MySQLTransactionRollbackException extends java.sql.SQLException
implements DeadlockTimeoutRollbackMarker {
public MySQLTransactionRollbackException();
public MySQLTransactionRollbackException(String message);
}
public interface DeadlockTimeoutRollbackMarker {
// Marker interface for deadlock/timeout exceptions
}Exceptions for data type conversion errors.
package com.mysql.cj.exceptions;
public class DataConversionException extends CJException {
public DataConversionException(String message);
}
public class DataReadException extends CJException {
public DataReadException(String message);
public DataReadException(Throwable cause);
}
public class DataTruncationException extends CJException {
public DataTruncationException(String message);
}
public class NumberOutOfRange extends CJException {
public NumberOutOfRange(String message);
}
package com.mysql.cj.jdbc.exceptions;
public class MysqlDataTruncation extends java.sql.DataTruncation {
public MysqlDataTruncation(String message, int index, boolean parameter,
boolean read, int dataSize, int transferSize, int vendorErrorCode);
}Exceptions for invalid connection states.
package com.mysql.cj.exceptions;
public class ConnectionIsClosedException extends CJException {
public ConnectionIsClosedException();
public ConnectionIsClosedException(String message);
}
public class StatementIsClosedException extends CJException {
public StatementIsClosedException();
public StatementIsClosedException(String message);
}
public class CJConnectionFeatureNotAvailableException extends CJException {
public CJConnectionFeatureNotAvailableException();
}
public class InvalidConnectionAttributeException extends CJException {
public InvalidConnectionAttributeException(String message);
}
package com.mysql.cj.jdbc.exceptions;
public class ConnectionFeatureNotAvailableException extends java.sql.SQLException {
public ConnectionFeatureNotAvailableException(String message, Throwable underlyingException);
}
public class NotUpdatable extends java.sql.SQLException {
public NotUpdatable(String message);
}Exceptions for unsupported operations.
package com.mysql.cj.exceptions;
public class CJOperationNotSupportedException extends CJException {
public CJOperationNotSupportedException();
public CJOperationNotSupportedException(String message);
}
public class FeatureNotAvailableException extends CJException {
public FeatureNotAvailableException(String message);
}
public class UnsupportedConnectionStringException extends CJException {
public UnsupportedConnectionStringException();
}
package com.mysql.cj.jdbc.exceptions;
public class OperationNotSupportedException extends java.sql.SQLException {
public OperationNotSupportedException();
public OperationNotSupportedException(String message);
}Exceptions for authentication and security failures.
package com.mysql.cj.exceptions;
public class PasswordExpiredException extends CJException {
public PasswordExpiredException();
public PasswordExpiredException(String message);
}
public class RSAException extends CJException {
public RSAException(String message);
public RSAException(String message, Throwable cause);
}
public class SSLParamsException extends CJException {
public SSLParamsException(String message);
public SSLParamsException(String message, Throwable cause);
}
package com.mysql.cj.jdbc.exceptions;
public class ClosedOnExpiredPasswordException extends java.sql.SQLException {
public ClosedOnExpiredPasswordException();
}Exceptions related to protocol violations.
package com.mysql.cj.exceptions;
public class CJPacketTooBigException extends CJException {
public CJPacketTooBigException();
public CJPacketTooBigException(String message);
}
public class WrongArgumentException extends CJException {
public WrongArgumentException(String message);
}
package com.mysql.cj.jdbc.exceptions;
public class PacketTooBigException extends java.sql.SQLException {
public PacketTooBigException(long packetSize);
}Exceptions for property handling.
package com.mysql.cj.exceptions;
public class PropertyNotModifiableException extends CJException {
public PropertyNotModifiableException(String message);
}Exception for assertion failures (should never occur in production).
package com.mysql.cj.exceptions;
public class AssertionFailedException extends CJException {
public AssertionFailedException(String message);
}Interface for intercepting and modifying exceptions.
package com.mysql.cj.exceptions;
public interface ExceptionInterceptor {
// Initialize interceptor
ExceptionInterceptor init(Properties props, Log log);
// Destroy interceptor
void destroy();
// Intercept exception
Exception interceptException(Exception sqlEx);
}
public class ExceptionInterceptorChain implements ExceptionInterceptor {
public ExceptionInterceptorChain(String interceptorClasses, Properties props, Log log);
public ExceptionInterceptor init(Properties props, Log log);
public void destroy();
public Exception interceptException(Exception sqlEx);
}Factory for creating exceptions with proper initialization.
package com.mysql.cj.exceptions;
public class ExceptionFactory {
// Create exception of specific type
public static <T extends CJException> T createException(Class<T> clazz, String message);
public static <T extends CJException> T createException(Class<T> clazz, String message,
ExceptionInterceptor exceptionInterceptor);
public static <T extends CJException> T createException(Class<T> clazz, Throwable cause);
public static <T extends CJException> T createException(Class<T> clazz, String message,
Throwable cause);
}Constants for MySQL server error numbers.
package com.mysql.cj.exceptions;
public class MysqlErrorNumbers {
// Connection errors
public static final int ER_SOCKET_UNEXPECTED_CLOSE = 2013;
// Access denied errors
public static final int ER_ACCESS_DENIED_ERROR = 1045;
// Password errors
public static final int ER_MUST_CHANGE_PASSWORD = 1820;
public static final int ER_MUST_CHANGE_PASSWORD_LOGIN = 1862;
// Deadlock and lock wait timeout
public static final int ER_LOCK_WAIT_TIMEOUT = 1205;
public static final int ER_LOCK_DEADLOCK = 1213;
// Constraint violations
public static final int ER_DUP_ENTRY = 1062;
public static final int ER_NO_REFERENCED_ROW = 1216;
public static final int ER_ROW_IS_REFERENCED = 1217;
// Table/database errors
public static final int ER_NO_SUCH_TABLE = 1146;
public static final int ER_BAD_DB_ERROR = 1049;
public static final int ER_BAD_TABLE_ERROR = 1051;
// Column errors
public static final int ER_BAD_FIELD_ERROR = 1054;
// Data errors
public static final int ER_DATA_TOO_LONG = 1406;
public static final int ER_TRUNCATED_WRONG_VALUE = 1292;
// Too many connections
public static final int ER_CON_COUNT_ERROR = 1040;
// Query errors
public static final int ER_SYNTAX_ERROR = 1064;
public static final int ER_PARSE_ERROR = 1064;
// ... many more error codes
}Utility for mapping MySQL errors to SQL states.
package com.mysql.cj.jdbc.exceptions;
public class SQLError {
// Create SQLException with proper SQL state
public static SQLException createSQLException(String message, String sqlState,
ExceptionInterceptor interceptor);
public static SQLException createSQLException(String message, String sqlState, int vendorErrorCode,
ExceptionInterceptor interceptor);
// Get localized message
public static String get(String key);
// SQL state constants
public static final String SQL_STATE_GENERAL_ERROR = "S1000";
public static final String SQL_STATE_COMMUNICATION_LINK_FAILURE = "08S01";
public static final String SQL_STATE_CONNECTION_NOT_OPEN = "08003";
public static final String SQL_STATE_CONNECTION_IN_USE = "08002";
public static final String SQL_STATE_ILLEGAL_ARGUMENT = "S1009";
public static final String SQL_STATE_SYNTAX_ERROR = "42000";
public static final String SQL_STATE_TIMEOUT_EXPIRED = "S1T00";
}
public class SQLExceptionsMapping {
// Map CJ exceptions to SQL exceptions
public static SQLException translateException(Throwable ex, ExceptionInterceptor interceptor);
}Exception for X DevAPI specific errors.
package com.mysql.cj.xdevapi;
public class XDevAPIError extends com.mysql.cj.exceptions.CJException {
public XDevAPIError(String message);
public XDevAPIError(String message, Throwable cause);
}Interface for streaming-related exceptions.
package com.mysql.cj.exceptions;
public interface StreamingNotifiable {
// Notify that streaming is in progress
void setWasStreamingResults();
}Usage examples:
// Catch specific exception
try {
conn.createStatement().executeQuery("SELECT * FROM users");
} catch (CommunicationsException e) {
System.out.println("Connection lost: " + e.getMessage());
// Attempt reconnection
}
// Handle timeout
try {
stmt.setQueryTimeout(5);
stmt.executeQuery("SELECT * FROM large_table");
} catch (MySQLTimeoutException e) {
System.out.println("Query timed out after 5 seconds");
}
// Handle deadlock
try {
// Perform transaction
} catch (MySQLTransactionRollbackException e) {
if (e instanceof DeadlockTimeoutRollbackMarker) {
System.out.println("Deadlock detected, retrying...");
// Retry transaction
}
}
// Check MySQL error code
try {
stmt.executeUpdate("INSERT INTO users (id, name) VALUES (1, 'Alice')");
} catch (SQLException e) {
if (e.getErrorCode() == MysqlErrorNumbers.ER_DUP_ENTRY) {
System.out.println("Duplicate key error");
}
}
// Use exception interceptor
String url = "jdbc:mysql://localhost:3306/mydb" +
"?exceptionInterceptors=com.mycompany.MyExceptionInterceptor";
Connection conn = DriverManager.getConnection(url);Install with Tessl CLI
npx tessl i tessl/maven-com-mysql--mysql-connector-j