Empire-DB
  1. Empire-DB
  2. EMPIREDB-122

Chinese characters being inserted as ??? on SqlServer (non-prepared statement)

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: empire-db-2.2.0-incubating
    • Fix Version/s: empire-db-2.3.0
    • Component/s: Core
    • Labels:

      Description

      Reported by Ben Ng

      Hi Empire-DB team,

      I am trying to insert a record with Chinese character from my JSP page.
      The encoding is set to UTF-8 already and I am trying to insert the record by the code below where "remarks" is a string contain Chinese characters.

      DBRecord rec = new DBRecord();
      rec.create(db.REQUESTS);
      rec.setValue(db.REQUESTS.REMARKS, remarks);
      rec.update(conn);

      After inserting the record, the data of the field REMARKS become "???".

      I tried to use traditional method(PreparedStatement) to insert this record by using the same db and connection.
      The data can be inserted correctly.
      Is there any step I have missed in my code so it can support UTF-8?

      I really appreciate for what your team have done. Thanks a lot.

      Thanks & Regards,
      Ben

        Activity

        Hide
        Francis De Brabandere added a comment -

        Good news, this can be fixed and has to be fixed on our side. In
        sqlserver you have to prepend your string with N for unicode, for
        example:
        INSERT INTO DEPARTMENTS( NAME, BUSINESS_UNIT, UPDATE_TIMESTAMP) VALUES
        ( N'junit', N'中文', '2011-11-09 20:28:40.718')

        Change DBDatabaseDriver line 664 to the following to fix the issue:
        valBuf.append("N'");

        Rainer, how would we fix this? getValueString() in DBDatabaseDriver is
        final. We could do this by default or have an option to enable the
        N's.

        Show
        Francis De Brabandere added a comment - Good news, this can be fixed and has to be fixed on our side. In sqlserver you have to prepend your string with N for unicode, for example: INSERT INTO DEPARTMENTS( NAME, BUSINESS_UNIT, UPDATE_TIMESTAMP) VALUES ( N'junit', N'中文', '2011-11-09 20:28:40.718') Change DBDatabaseDriver line 664 to the following to fix the issue: valBuf.append("N'"); Rainer, how would we fix this? getValueString() in DBDatabaseDriver is final. We could do this by default or have an option to enable the N's.
        Hide
        Francis De Brabandere added a comment -

        I'm assigning this to Rainer as I need some input on how to fix this.

        Show
        Francis De Brabandere added a comment - I'm assigning this to Rainer as I need some input on how to fix this.
        Hide
        Rainer Döbele added a comment -

        added override to DBDatabaseDriverMSSQL:
        Function getSQLTextString() will add a Unicode Prefix (N) depending on property useUnicodePrefix. Default is true.

        Show
        Rainer Döbele added a comment - added override to DBDatabaseDriverMSSQL: Function getSQLTextString() will add a Unicode Prefix (N) depending on property useUnicodePrefix. Default is true.
        Hide
        Rainer Döbele added a comment -

        Cleanup of unclosed issues.

        Show
        Rainer Döbele added a comment - Cleanup of unclosed issues.

          People

          • Assignee:
            Rainer Döbele
            Reporter:
            Francis De Brabandere
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development