Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8144082

Add Statement.enquoteNCharLiteral to support National Character Set literals

XMLWordPrintable

    • b101

      Add the following method to Statement:
          /**
          * Returns a {@code String} representing a National Character Set Literal
          * enclosed in single quotes and prefixed with a upper case letter N.
          * Any occurrence of a single quote within the string will be replaced
          * by two single quotes.
          *
          * <blockquote>
          * <table border = 1 cellspacing=0 cellpadding=5 >
          * <caption>Examples of the conversion:</caption>
          * <tr>
          * <th>Value</th>
          * <th>Result</th>
          * </tr>
          * <tr> <td align='center'>Hello</td> <td align='center'>N'Hello'</td> </tr>
          * <tr> <td align='center'>G'Day</td> <td align='center'>N'G''Day'</td> </tr>
          * <tr> <td align='center'>'G''Day'</td>
          * <td align='center'>N'''G''''Day'''</td> </tr>
          * <tr> <td align='center'>I'''M</td> <td align='center'>N'I''''''M'</td>
          * </tr>
          *
          * </table>
          * </blockquote>
          * @implNote
          * JDBC driver implementations may need to provide their own implementation
          * of this method in order to meet the requirements of the underlying
          * datasource. An implementation of enquoteNCharLiteral may accept a different
          * set of characters than that accepted by the same driver’s implementation of
          * enquoteLiteral.
          * @param val a character string
          * @return A string enclosed by single quotes with every single quote
          * converted to two single quotes and prefixed by ’N'
          * @throws NullPointerException if val is {@code null}
          * @throws SQLException if a database access error occurs
          */
          default String enquoteNCharLiteral(String val) throws SQLException {
              return "N'" + val.replace("'", "''") + "'";
         }

            lancea Lance Andersen
            lancea Lance Andersen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: