UTF - 8 with JPA and Glassfish 4.0

后端 未结 2 2040
無奈伤痛
無奈伤痛 2020-12-28 10:37

I am having difficulties with UTF-8 characters. This is a simple JSF project. I use JSF 2.2 and Glassfish 4.0

I have a method where I go:

em.persist(         


        
相关标签:
2条回答
  • 2020-12-28 11:11

    When using Glassfish, you can set these properties as additional to your JDBC Connection Pools. Locate and view your database connection in Web Administration (Resources->JDBC Connection Pools->your.connection). In additional properties tab add (if there are not present yet) mentioned properties and restart your server:

    //name, value
    characterEncoding, UTF-8
    characterSetResults, UTF-8
    useUnicode, true
    

    The result will be the same if parameters are added to URL, but this is more maintainable solution in my opinion.

    0 讨论(0)
  • 2020-12-28 11:26

    This solved it:

    jdbc:mysql://localhost:3306/fus?useUnicode=true&characterEncoding=UTF-8&characterSetResults=UTF-8

    so this was wrong:

    jdbc:mysql://localhost:3306/fus?useUnicode=true&connectionCollation=utf8_general_ci&characterSetResults=utf8

    0 讨论(0)
提交回复
热议问题