Why do Unicode characters show up properly in database, but as ? when printed in Java via Hibernate?
        Posted  
        
            by lupefiasco
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by lupefiasco
        
        
        
        Published on 2010-04-09T01:41:31Z
        Indexed on 
            2010/04/09
            1:53 UTC
        
        
        Read the original article
        Hit count: 500
        
I'm writing a webapp, and interfacing with MySQL using Hibernate 3.5. Using "?????? ?????????" as my test string, I can input the string and see that it is properly persisted into the database. However, when I later pull the value out of the database and print to the console as a String, I see "?????? ?????????". If I use
new OutputStreamWriter(System.out,"UTF-8");
then I get "„Éá„Çp„ÇØ„Éà„ÉÉ„Éó ·Éò·Éú·Éí·Éö·Éò·É°·É£·É†·Éò"". Why don't I see the original string?
These are my hibernate.cfg.xml settings:
<property name="hibernate.connection.useUnicode">
    true
</property>
<property name="hibernate.connection.characterEncoding">
    UTF-8
</property>
<property name="hibernate.connection.charSet">
    UTF-8
</property>
and this is my database connection string:
hibernate.connection.url = jdbc:mysql://localhost/mydatabase?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8
        © Stack Overflow or respective owner