diff -r 3f251ae0f2d3 -r b088bf935e4b jdk/src/java.sql/share/classes/java/sql/Statement.java --- a/jdk/src/java.sql/share/classes/java/sql/Statement.java Wed Nov 25 09:23:07 2015 +0100 +++ b/jdk/src/java.sql/share/classes/java/sql/Statement.java Wed Nov 25 15:28:30 2015 -0500 @@ -1397,9 +1397,10 @@ * @param val a character string * @return A string enclosed by single quotes with every single quote * converted to two single quotes - * @throws NullPointerException if val is null + * @throws NullPointerException if val is {@code null} + * @throws SQLException if a database access error occurs */ - default String enquoteLiteral(String val) { + default String enquoteLiteral(String val) throws SQLException { return "'" + val.replace("'", "''") + "'"; } @@ -1437,7 +1438,7 @@ * * The default implementation will throw a {@code SQLException} if: * @@ -1501,14 +1502,14 @@ * @throws SQLException if identifier is not a valid identifier * @throws SQLFeatureNotSupportedException if the datasource does not support * delimited identifiers - * @throws NullPointerException if identifier is null + * @throws NullPointerException if identifier is {@code null} */ default String enquoteIdentifier(String identifier, boolean alwaysQuote) throws SQLException { int len = identifier.length(); if (len < 1 || len > 128) { throw new SQLException("Invalid name"); } - if (Pattern.compile("[\\p{Alpha}][\\p{Alnum}_]+").matcher(identifier).matches()) { + if (Pattern.compile("[\\p{Alpha}][\\p{Alnum}_]*").matcher(identifier).matches()) { return alwaysQuote ? "\"" + identifier + "\"" : identifier; } if (identifier.matches("^\".+\"$")) { @@ -1520,4 +1521,65 @@ throw new SQLException("Invalid name"); } } + + /** + * Retrieves whether {@code identifier} is a simple SQL identifier. + * + * @implSpec The default implementation uses the following criteria to + * determine a valid simple SQL identifier: + * + * + *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + *
Examples of the conversion:
identifierSimple Identifier
Hellotrue
G'Dayfalse
"Bruce Wayne"false
GoodDay$false
Hello"Worldfalse
"Hello"World"false
+ *
+ * @implNote JDBC driver implementations may need to provide their own + * implementation of this method in order to meet the requirements of the + * underlying datasource. + * @param identifier a SQL identifier + * @return true if a simple SQL identifier, false otherwise + * @throws NullPointerException if identifier is {@code null} + * @throws SQLException if a database access error occurs + */ + default boolean isSimpleIdentifier(String identifier) throws SQLException { + int len = identifier.length(); + return len >= 1 && len <= 128 + && Pattern.compile("[\\p{Alpha}][\\p{Alnum}_]*").matcher(identifier).matches(); + } }