Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-1335

The object names in SQLException messages are not in UTF-16

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 10.1.2.1
    • 10.1.3.1
    • Network Client
    • None
    • Debian unstable, Linux 2.6.14.2, libc 2.3.5-8, Sun JDK 1.5.0_05-b05, Derby 10.1.2.1

    Description

      The object names in SQLException messages are not in UTF-16, although they are sent to the server in that encoding. For example, when adding a both NULL and UNIQUE column the resulting exception message will contain the column name (like in "'é' cannot be a column of a primary key or unique key because it can contain null values.'). If the column name contained characters outside the range U+0000..U+007F these characters are not encoded in UTF-16 in the exception message. Can only reproduce with the client driver, the embedded driver behaves as expected.

      Code to reproduce the issue (have a database called "sample" containing a table called "TEST"):

      ----%<----
      import java.sql.Connection;
      import java.sql.DriverManager;
      import java.sql.SQLException;
      import java.sql.Statement;

      public class MainDerby {

      public static void main(String[] args) throws Exception {
      Class.forName("org.apache.derby.jdbc.ClientDriver");

      Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
      try

      { String tableName = "é"; System.out.println("Table name code point: " + (int)tableName.charAt(0)); Statement stmt = conn.createStatement(); stmt.executeUpdate("ALTER TABLE test ADD \"" + tableName + "\" INT UNIQUE"); }

      catch (SQLException e) {
      String message = e.getMessage(); // '??' cannot be a column of a primary key or unique key because it can contain null values.
      System.out.println("Exception message: " + message);
      System.out.print("Table name code points in exception message: ");
      if (message.charAt(0) == '\'') { //
      int i = 1;
      char ch = message.charAt;
      while (ch != '\'')

      { System.out.print((int)ch); System.out.print(" "); i++; ch = message.charAt(i); }

      }
      System.out.println();
      } finally

      { conn.close(); }

      }
      }
      ----%<----

      This program produces the following output:

      ----%<----
      Table name code point: 233
      Exception message: '??' cannot be a column of a primary key or unique key because it can contain null values.
      Table name code points in exception message: 258 352
      ----%<----

      Note "??" is the UTF-8 representation of "é".

      This was initially reported as NetBeans issue 76584 (http://www.netbeans.org/issues/show_bug.cgi?id=76584).

      Attachments

        Activity

          People

            Unassigned Unassigned
            andrei.badea Andrei Badea
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: