Java + Mysql UTF8 Problem

前端 未结 2 840
半阙折子戏
半阙折子戏 2020-11-30 04:56

as the title said, I have a problem between java and mysql

The mysql DB, tables, and columns are utf8_unicode_ci. I have an application that took some input from an

2条回答
  •  日久生厌
    2020-11-30 05:12

    Solved, I forgot to add the encoding when initializing Connection:

    before was:

    con = DriverManager.getConnection("jdbc:mysql:///dbname", "user", "pass");

    now (working):

    con = DriverManager.getConnection("jdbc:mysql:///dbname?useUnicode=true&characterEncoding=utf-8", "user", "pass");

提交回复
热议问题