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: *
+ *+ * @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(); + } }+ *
+ *Examples of the conversion: + *+ * identifier + *Simple Identifier + * + *+ * + *Hello + *true + *+ * + *G'Day + *false + *+ * + *"Bruce Wayne" + *false + *+ * + *GoodDay$ + *false + *+ * + *Hello"World + *false + *+ * + *"Hello"World" + *false + *