public default String enquoteIdentifier (String identifier, boolean alwaysQuote) throws SQLException

Returns a SQL identifier. If identifier is a simple SQL identifier:

If identifier is not a simple SQL identifier, identifier will be enclosed in double quotes if not already present. If the datasource does not support double quotes for delimited identifiers, the identifier should be enclosed by the string returned from DatabaseMetaData.getIdentifierQuoteString. If the datasource does not support delimited identifiers, a SQLFeatureNotSupportedException should be thrown.

A SQLException will be thrown if identifier contains any characters invalid in a delimited identifier or the identifier length is invalid for the datasource.

Parameters:
identifier    a SQL identifier
alwaysQuote    indicates if a simple SQL identifier should be returned as a quoted identifier

Returns:  A simple SQL identifier or a delimited identifier

Exceptions:
SQLException    if identifier is not a valid identifier
SQLFeatureNotSupportedException    if the datasource does not support delimited identifiers
NullPointerException    if identifier is null

Since:  9

@implSpec The default implementation uses the following criteria to determine a valid simple SQL identifier:

The default implementation will throw a SQLException if:
Examples of the conversion:
identifier alwaysQuote Result
Hello false Hello
Hello true "Hello"
G'Day false "G'Day"
"Bruce Wayne" false "Bruce Wayne"
"Bruce Wayne" true "Bruce Wayne"
GoodDay$ false "GoodDay$"
Hello"World false SQLException
"Hello"World" false SQLException

@implNote JDBC driver implementations may need to provide their own implementation of this method in order to meet the requirements of the underlying datasource.