Class DatabaseException

java.lang.Object
java.lang.Throwable
java.lang.Exception
is.codion.common.db.exception.DatabaseException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
AuthenticationException, DeleteException, MultipleRecordsFoundException, QueryTimeoutException, RecordNotFoundException, ReferentialIntegrityException, UniqueConstraintException, UpdateException

public class DatabaseException extends Exception
An exception coming from a database-layer.
See Also:
  • Constructor Details

    • DatabaseException

      public DatabaseException(String message)
      Constructs a new DatabaseException instance
      Parameters:
      message - the exception message
    • DatabaseException

      public DatabaseException(String message, String statement)
      Constructs a new DatabaseException instance
      Parameters:
      message - the exception message
      statement - the sql statement which caused the exception
    • DatabaseException

      public DatabaseException(SQLException cause)
      Constructs a new DatabaseException instance
      Parameters:
      cause - the root cause, the stack trace is copied and used
    • DatabaseException

      public DatabaseException(SQLException cause, String message)
      Constructs a new DatabaseException instance
      Parameters:
      cause - the root cause, the stack trace is copied and used
      message - the exception message
    • DatabaseException

      public DatabaseException(SQLException cause, String message, String statement)
      Constructs a new DatabaseException instance
      Parameters:
      cause - the root cause, the stack trace is copied and used
      message - the exception message
      statement - the sql statement which caused the exception
  • Method Details

    • statement

      public final Optional<String> statement()
      Returns the sql statement causing this exception, if available, note that this is only available when running with a local database connection.
      Returns:
      the sql statement which caused the exception, an empty Optional if not avialable
    • errorCode

      public final int errorCode()
      Returns the underlying error code, note that this is only available when running with a local database connection.
      Returns:
      the underlying error code, -1 if not available
    • sqlState

      public final Optional<String> sqlState()
      Returns the underlying sql state, note that this is only available when running with a local database connection.
      Returns:
      the underlying sql state, an empty Optional if not available
    • setStackTrace

      public final void setStackTrace(StackTraceElement[] stackTrace)
      Overrides:
      setStackTrace in class Throwable