Class DbException

All Implemented Interfaces:
Serializable

public class DbException extends RuntimeException
This exception wraps a checked exception. It is used in methods where checked exceptions are not supported, for example in a Comparator.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • HIDE_SQL

      public static final String HIDE_SQL
      If the SQL statement contains this text, then it is never added to the SQL exception. Hiding the SQL statement may be important if it contains a passwords, such as a CREATE LINKED TABLE statement.
      See Also:
    • MESSAGES

      private static final Properties MESSAGES
    • SQL_OOME

      public static final SQLException SQL_OOME
      Thrown when OOME exception happens on handle error inside convert(java.lang.Throwable).
    • OOME

      private static final DbException OOME
    • source

      private Object source
  • Constructor Details

  • Method Details

    • translate

      private static String translate(String key, String... params)
    • quote

      private static String quote(String s)
    • getSQLException

      public SQLException getSQLException()
      Get the SQLException object.
      Returns:
      the exception
    • getErrorCode

      public int getErrorCode()
      Get the error code.
      Returns:
      the error code
    • addSQL

      public DbException addSQL(String sql)
      Set the SQL statement of the given exception. This method may create a new object.
      Parameters:
      sql - the SQL statement
      Returns:
      the exception
    • get

      public static DbException get(int errorCode)
      Create a database exception for a specific error code.
      Parameters:
      errorCode - the error code
      Returns:
      the exception
    • get

      public static DbException get(int errorCode, String p1)
      Create a database exception for a specific error code.
      Parameters:
      errorCode - the error code
      p1 - the first parameter of the message
      Returns:
      the exception
    • get

      public static DbException get(int errorCode, Throwable cause, String... params)
      Create a database exception for a specific error code.
      Parameters:
      errorCode - the error code
      cause - the cause of the exception
      params - the list of parameters of the message
      Returns:
      the exception
    • get

      public static DbException get(int errorCode, String... params)
      Create a database exception for a specific error code.
      Parameters:
      errorCode - the error code
      params - the list of parameters of the message
      Returns:
      the exception
    • fromUser

      public static DbException fromUser(String sqlstate, String message)
      Create a database exception for an arbitrary SQLState.
      Parameters:
      sqlstate - the state to use
      message - the message to use
      Returns:
      the exception
    • getSyntaxError

      public static DbException getSyntaxError(String sql, int index)
      Create a syntax error exception.
      Parameters:
      sql - the SQL statement
      index - the position of the error in the SQL statement
      Returns:
      the exception
    • getSyntaxError

      public static DbException getSyntaxError(String sql, int index, String message)
      Create a syntax error exception.
      Parameters:
      sql - the SQL statement
      index - the position of the error in the SQL statement
      message - the message
      Returns:
      the exception
    • getSyntaxError

      public static DbException getSyntaxError(int errorCode, String sql, int index, String... params)
      Create a syntax error exception for a specific error code.
      Parameters:
      errorCode - the error code
      sql - the SQL statement
      index - the position of the error in the SQL statement
      params - the list of parameters of the message
      Returns:
      the exception
    • getUnsupportedException

      public static DbException getUnsupportedException(String message)
      Gets a SQL exception meaning this feature is not supported.
      Parameters:
      message - what exactly is not supported
      Returns:
      the exception
    • getInvalidValueException

      public static DbException getInvalidValueException(String param, Object value)
      Gets a SQL exception meaning this value is invalid.
      Parameters:
      param - the name of the parameter
      value - the value passed
      Returns:
      the exception
    • getInvalidExpressionTypeException

      public static DbException getInvalidExpressionTypeException(String param, Typed e)
      Gets a SQL exception meaning the type of expression is invalid or unknown.
      Parameters:
      param - the name of the parameter
      e - the expression
      Returns:
      the exception
    • getValueTooLongException

      public static DbException getValueTooLongException(String columnOrType, String value, long valueLength)
      Gets a SQL exception meaning this value is too long.
      Parameters:
      columnOrType - column with data type or data type name
      value - string representation of value, will be truncated to 80 characters
      valueLength - the actual length of value, -1L if unknown
      Returns:
      the exception
    • getFileVersionError

      public static DbException getFileVersionError(String dataFileName)
      Gets a file version exception.
      Parameters:
      dataFileName - the name of the database
      Returns:
      the exception
    • getInternalError

      public static RuntimeException getInternalError(String s)
      Gets an internal error.
      Parameters:
      s - the message
      Returns:
      the RuntimeException object
    • getInternalError

      public static RuntimeException getInternalError()
      Gets an internal error.
      Returns:
      the RuntimeException object
    • toSQLException

      public static SQLException toSQLException(Throwable e)
      Convert an exception to a SQL exception using the default mapping.
      Parameters:
      e - the root cause
      Returns:
      the SQL exception object
    • convert

      public static DbException convert(Throwable e)
      Convert a throwable to an SQL exception using the default mapping. All errors except the following are re-thrown: StackOverflowError, LinkageError.
      Parameters:
      e - the root cause
      Returns:
      the exception object
    • convertInvocation

      public static DbException convertInvocation(InvocationTargetException te, String message)
      Convert an InvocationTarget exception to a database exception.
      Parameters:
      te - the root cause
      message - the added message or null
      Returns:
      the database exception object
    • convertIOException

      public static DbException convertIOException(IOException e, String message)
      Convert an IO exception to a database exception.
      Parameters:
      e - the root cause
      message - the message or null
      Returns:
      the database exception object
    • getJdbcSQLException

      public static SQLException getJdbcSQLException(int errorCode)
      Gets the SQL exception object for a specific error code.
      Parameters:
      errorCode - the error code
      Returns:
      the SQLException object
    • getJdbcSQLException

      public static SQLException getJdbcSQLException(int errorCode, String p1)
      Gets the SQL exception object for a specific error code.
      Parameters:
      errorCode - the error code
      p1 - the first parameter of the message
      Returns:
      the SQLException object
    • getJdbcSQLException

      public static SQLException getJdbcSQLException(int errorCode, Throwable cause, String... params)
      Gets the SQL exception object for a specific error code.
      Parameters:
      errorCode - the error code
      cause - the cause of the exception
      params - the list of parameters of the message
      Returns:
      the SQLException object
    • getJdbcSQLException

      public static SQLException getJdbcSQLException(String message, String sql, String state, int errorCode, Throwable cause, String stackTrace)
      Creates a SQLException.
      Parameters:
      message - the reason
      sql - the SQL statement
      state - the SQL state
      errorCode - the error code
      cause - the exception that was the reason for this exception
      stackTrace - the stack trace
      Returns:
      the SQLException object
    • filterSQL

      private static String filterSQL(String sql)
    • buildMessageForException

      public static String buildMessageForException(JdbcException e)
      Builds message for an exception.
      Parameters:
      e - exception
      Returns:
      message
    • printNextExceptions

      public static void printNextExceptions(SQLException e, PrintWriter s)
      Prints up to 100 next exceptions for a specified SQL exception.
      Parameters:
      e - SQL exception
      s - print writer
    • printNextExceptions

      public static void printNextExceptions(SQLException e, PrintStream s)
      Prints up to 100 next exceptions for a specified SQL exception.
      Parameters:
      e - SQL exception
      s - print stream
    • getSource

      public Object getSource()
    • setSource

      public void setSource(Object source)
    • traceThrowable

      public static void traceThrowable(Throwable e)
      Write the exception to the driver manager log writer if configured.
      Parameters:
      e - the exception