Class SQLError

java.lang.Object
com.mysql.jdbc.SQLError

public class SQLError extends Object
SQLError is a utility class that maps MySQL error codes to X/Open error codes as is required by the JDBC spec.
  • Field Details

  • Constructor Details

    • SQLError

      public SQLError()
  • Method Details

    • convertShowWarningsToSQLWarnings

      static SQLWarning convertShowWarningsToSQLWarnings(Connection connection) throws SQLException
      Turns output of 'SHOW WARNINGS' into JDBC SQLWarning instances. If 'forTruncationOnly' is true, only looks for truncation warnings, and actually throws DataTruncation as an exception.
      Parameters:
      connection - the connection to use for getting warnings.
      Returns:
      the SQLWarning chain (or null if no warnings)
      Throws:
      SQLException - if the warnings could not be retrieved
    • convertShowWarningsToSQLWarnings

      static SQLWarning convertShowWarningsToSQLWarnings(Connection connection, int warningCountIfKnown, boolean forTruncationOnly) throws SQLException
      Turns output of 'SHOW WARNINGS' into JDBC SQLWarning instances. If 'forTruncationOnly' is true, only looks for truncation warnings, and actually throws DataTruncation as an exception.
      Parameters:
      connection - the connection to use for getting warnings.
      warningCountIfKnown - the warning count (if known), otherwise set it to 0.
      forTruncationOnly - if this method should only scan for data truncation warnings
      Returns:
      the SQLWarning chain (or null if no warnings)
      Throws:
      SQLException - if the warnings could not be retrieved, or if data truncation is being scanned for and truncations were found.
    • dumpSqlStatesMappingsAsXml

      public static void dumpSqlStatesMappingsAsXml() throws Exception
      Throws:
      Exception
    • get

      static String get(String stateCode)
    • mysqlToSqlState

      static String mysqlToSqlState(int errno, boolean useSql92States)
      Map MySQL error codes to X/Open or SQL-92 error codes
      Parameters:
      errno - the MySQL error code
      Returns:
      the corresponding X/Open or SQL-92 error code
    • createSQLException

      public static SQLException createSQLException(String message, String sqlState, ExceptionInterceptor interceptor)
    • createSQLException

      public static SQLException createSQLException(String message, ExceptionInterceptor interceptor)
    • createSQLException

      public static SQLException createSQLException(String message, ExceptionInterceptor interceptor, Connection conn)
    • createSQLException

      public static SQLException createSQLException(String message, String sqlState, Throwable cause, ExceptionInterceptor interceptor)
    • createSQLException

      public static SQLException createSQLException(String message, String sqlState, Throwable cause, ExceptionInterceptor interceptor, Connection conn)
    • createSQLException

      public static SQLException createSQLException(String message, String sqlState, int vendorErrorCode, ExceptionInterceptor interceptor)
    • createSQLException

      public static SQLException createSQLException(String message, String sqlState, int vendorErrorCode, boolean isTransient, ExceptionInterceptor interceptor)
      Parameters:
      message -
      sqlState -
      vendorErrorCode -
      isTransient -
      interceptor -
    • createSQLException

      public static SQLException createSQLException(String message, String sqlState, int vendorErrorCode, boolean isTransient, ExceptionInterceptor interceptor, Connection conn)
    • createCommunicationsException

      public static SQLException createCommunicationsException(MySQLConnection conn, long lastPacketSentTimeMs, long lastPacketReceivedTimeMs, Exception underlyingException, ExceptionInterceptor interceptor)
    • createLinkFailureMessageBasedOnHeuristics

      public static String createLinkFailureMessageBasedOnHeuristics(MySQLConnection conn, long lastPacketSentTimeMs, long lastPacketReceivedTimeMs, Exception underlyingException)
      Creates a communications link failure message to be used in CommunicationsException that (hopefully) has some better information and suggestions based on heuristics.
      Parameters:
      conn -
      lastPacketSentTimeMs -
      underlyingException -
    • createBatchUpdateException

      public static SQLException createBatchUpdateException(SQLException underlyingEx, long[] updateCounts, ExceptionInterceptor interceptor) throws SQLException
      Create a BatchUpdateException taking in consideration the JDBC version in use. For JDBC version prior to 4.2 the updates count array has int elements while JDBC 4.2 and beyond uses long values.
      Parameters:
      underlyingEx -
      updateCounts -
      interceptor -
      Throws:
      SQLException
    • createSQLFeatureNotSupportedException

      public static SQLException createSQLFeatureNotSupportedException() throws SQLException
      Create a SQLFeatureNotSupportedException or a NotImplemented exception according to the JDBC version in use.
      Throws:
      SQLException
    • createSQLFeatureNotSupportedException

      public static SQLException createSQLFeatureNotSupportedException(String message, String sqlState, ExceptionInterceptor interceptor) throws SQLException
      Create a SQLFeatureNotSupportedException or a NotImplemented exception according to the JDBC version in use.
      Parameters:
      message -
      sqlState -
      interceptor -
      Throws:
      SQLException