Package org.apache.commons.dbcp2

## Class Utils

- java.lang.Object
- - org.apache.commons.dbcp2.Utils

-     public final class Utils
      extends Object

  Utility methods.
  Since:
    2.0

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static String` | `DISCONNECTION_SQL_CODE_PREFIX` | Any SQL_STATE starting with this value is considered a fatal disconnect
    `static Set<String>` | `DISCONNECTION_SQL_CODES` | Deprecated. Use `getDisconnectionSqlCodes()`.
    `static boolean` | `IS_SECURITY_ENABLED` | Deprecated. No replacement.

  - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `static char[]` | `clone​(char[] value)` | Clones the given char[] if not null.
    `static Properties` | `cloneWithoutCredentials​(Properties properties)` | Clones the given `Properties` without the standard "user" or "password" entries.
    `static void` | `close​(AutoCloseable autoCloseable, Consumer<Exception> exceptionHandler)` | Closes the given `AutoCloseable` and if an exception is caught, then calls `exceptionHandler`.
    `static void` | `closeQuietly​(AutoCloseable autoCloseable)` | Closes the AutoCloseable (which may be null).
    `static void` | `closeQuietly​(Connection connection)` | Deprecated. Use `closeQuietly(AutoCloseable)`.
    `static void` | `closeQuietly​(ResultSet resultSet)` | Deprecated. Use `closeQuietly(AutoCloseable)`.
    `static void` | `closeQuietly​(Statement statement)` | Deprecated. Use `closeQuietly(AutoCloseable)`.
    `static Set<String>` | `getDisconnectionSqlCodes()` | Gets a copy of SQL codes of fatal connection errors.
    `static String` | `getMessage​(String key)` | Gets the correct i18n message for the given key.
    `static String` | `getMessage​(String key, Object... args)` | Gets the correct i18n message for the given key with placeholders replaced by the supplied arguments.
    `static char[]` | `toCharArray​(String value)` | Converts the given String to a char[].
    `static String` | `toString​(char[] value)` | Converts the given char[] to a String.
    `static void` | `validateLifetime​(PooledObject<?> p, Duration maxDuration)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### IS_SECURITY_ENABLED

          @Deprecated
          public static final boolean IS_SECURITY_ENABLED

      Deprecated.
      No replacement.
      Whether the security manager is enabled.

    - #### DISCONNECTION_SQL_CODE_PREFIX

          public static final String DISCONNECTION_SQL_CODE_PREFIX

      Any SQL_STATE starting with this value is considered a fatal disconnect
      See Also:
        Constant Field Values

    - #### DISCONNECTION_SQL_CODES

          @Deprecated
          public static final Set<String> DISCONNECTION_SQL_CODES

      Deprecated.
      Use `getDisconnectionSqlCodes()`.
      SQL codes of fatal connection errors.
      - 57P01 (Admin shutdown)
      - 57P02 (Crash shutdown)
      - 57P03 (Cannot connect now)
      - 01002 (SQL92 disconnect error)
      - JZ0C0 (Sybase disconnect error)
      - JZ0C1 (Sybase disconnect error)

  - ### Method Detail

    - #### clone

          public static char[] clone​(char[] value)

      Clones the given char[] if not null.
      Parameters:
        `value` - may be null.
      Returns:
        a cloned char[] or null.

    - #### cloneWithoutCredentials

          public static Properties cloneWithoutCredentials​(Properties properties)

      Clones the given `Properties` without the standard "user" or "password" entries.
      Parameters:
        `properties` - may be null
      Returns:
        a clone of the input without the standard "user" or "password" entries.
      Since:
        2.8.0

    - #### close

          public static void close​(AutoCloseable autoCloseable,
                                   Consumer<Exception> exceptionHandler)

      Closes the given `AutoCloseable` and if an exception is caught, then calls `exceptionHandler`.
      Parameters:
        `autoCloseable` - The resource to close.
        `exceptionHandler` - Consumes exception thrown closing this resource.
      Since:
        2.10.0

    - #### closeQuietly

          public static void closeQuietly​(AutoCloseable autoCloseable)

      Closes the AutoCloseable (which may be null).
      Parameters:
        `autoCloseable` - an AutoCloseable, may be `null`
      Since:
        2.6.0

    - #### closeQuietly

          @Deprecated
          public static void closeQuietly​(Connection connection)

      Deprecated.
      Use `closeQuietly(AutoCloseable)`.
      Closes the Connection (which may be null).
      Parameters:
        `connection` - a Connection, may be `null`

    - #### closeQuietly

          @Deprecated
          public static void closeQuietly​(ResultSet resultSet)

      Deprecated.
      Use `closeQuietly(AutoCloseable)`.
      Closes the ResultSet (which may be null).
      Parameters:
        `resultSet` - a ResultSet, may be `null`

    - #### closeQuietly

          @Deprecated
          public static void closeQuietly​(Statement statement)

      Deprecated.
      Use `closeQuietly(AutoCloseable)`.
      Closes the Statement (which may be null).
      Parameters:
        `statement` - a Statement, may be `null`.

    - #### getDisconnectionSqlCodes

          public static Set<String> getDisconnectionSqlCodes()

      Gets a copy of SQL codes of fatal connection errors.
      - 57P01 (Admin shutdown)
      - 57P02 (Crash shutdown)
      - 57P03 (Cannot connect now)
      - 01002 (SQL92 disconnect error)
      - JZ0C0 (Sybase disconnect error)
      - JZ0C1 (Sybase disconnect error)
      Returns:
        SQL codes of fatal connection errors.
      Since:
        2.10.0

    - #### getMessage

          public static String getMessage​(String key)

      Gets the correct i18n message for the given key.
      Parameters:
        `key` - The key to look up an i18n message.
      Returns:
        The i18n message.

    - #### getMessage

          public static String getMessage​(String key,
                                          Object... args)

      Gets the correct i18n message for the given key with placeholders replaced by the supplied arguments.
      Parameters:
        `key` - A message key.
        `args` - The message arguments.
      Returns:
        An i18n message.

    - #### toCharArray

          public static char[] toCharArray​(String value)

      Converts the given String to a char[].
      Parameters:
        `value` - may be null.
      Returns:
        a char[] or null.

    - #### toString

          public static String toString​(char[] value)

      Converts the given char[] to a String.
      Parameters:
        `value` - may be null.
      Returns:
        a String or null.

    - #### validateLifetime

          public static void validateLifetime​(PooledObject<?> p,
                                              Duration maxDuration)
                                       throws org.apache.commons.dbcp2.LifetimeExceededException

      Throws:
        `org.apache.commons.dbcp2.LifetimeExceededException`