2 Replies Latest reply on Apr 15, 2002 12:02 PM by ywhking

    mySQl through Jboss 2.4 CMP encoding problem

    rsivanov

      Hi, all.

      We run into trouble using MySQL 3.23.41 database and JBoss 2.4.0 jaws CMP. The problem is in the

      Cp1251 encoding. We used mm.mysql-2.0.6.1.jar JDBC driver, the documentation to that driver says

      "Since MySQL does not support Unicode directly, the MM.MySQL implementations of

      PreparedStatement.getXXXStream() expect that your JVM will be able to convert from the character

      set that MySQL uses to the default character set of your JVM, or the one you set using the

      useUnicode and encoding parameters." Here is the configuration of JDBC datasource for our mySQL

      database in the jboss.jcml:


      org.gjt.mm.mysql.Driver



      VDDataSource
      org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl
      jdbc:mysql://localhost/vertdiamond
      user
      password


      We also tried to use the other form of "URL":

      "jdbc:mysql://localhost/vertdiamond?useUnicode=true&characterEncoding=Cp1251", but JBoss throws

      parser exception (it crushes on "characterEncoding").

      As for MySQL configuration, we use these strings in my.ini:
      character-sets-dir=C:/mysql/share/charsets
      default-character-set=cp1251

      When we use our CMP entity bean "User", calling UserHome.create(name, surname, etc...), where

      name consists of cyrillic letters, JBoss jaws CMP inserts into the mySQL table a record, but in a

      wrong encoding (we can't see cyrillic).

      So, it seems to us that the problem with a wrong encoding is rather typical, but we don't know

      how to solve it. Please, help.

      Our email: digest_V@mail.ru

        • 1. mySQl encoding problem

          illegal XML characters have to be replaced by entity references:

          use these:

          &lt; < less than
          &gt; > greater than
          &amp; & ampersand
          &apos; ' apostrophe
          &quot; " quotation mark

          or use the CDATA section.
          Everything inside a CDATA section is ignored by the parser.

          If your text contains a lot of "<" or "&" characters - like program code often does - the XML element can be defined as a CDATA section.

          A CDATA section starts with "<![CDATA[" and ends with "]]>"

          your connect string inside the jboss.jcml should look like this:

          jdbc:mysql://localhost/vertdiamond?useUnicode=true&amp;characterEncoding=Cp1251

          joe

          • 2. Re: mySQl encoding problem
            ywhking

            Hi,joe
            I encountered a strange problem and need your help.
            I inserted a record in mySQL database by an EntityBean.Then when I querid it out it appeared mess.But when I restarted the jboss server,the data queried out appeared normal.
            I think it may be that the jboss server get data from different place.The first time it get data from the instance pool,then when the server restarted,it get data from database.But in these two situations the data have different encoding.The first time it have the encoding of iso-8859-1(database default encoding),the second time it have the encoding of gb2312(local encoding).I have changed the charsetEncoding to iso-8859-1 in the file jboss.jcml according to your reply.But the problem still happened.
            I don't know how to deal with this problem,could you please help me?
            My platform is Win2k(Chinese) + jboss-2.4.4 + mySQL-3.23.47.
            Thanks in advance.
            ywhking