zoukankan      html  css  js  c++  java
  • Is it a bug in MySQL or in java-connector?——转

    Description

             In mysql-connector-java-5.1.27, the charset utf8mb4 is supported. But the steps and result bellow looks buggy.

    1、  set character_set_server=gbk in my.cnf

    2、  start mysql

    3、  execute  set global character_set_server=utfmb4;

    4、  insert a data with utf8mb4 characters

    Result: error data inserted.

    Analysis

             Direct reason: Java connector believes that the server use gbk as the default set, so deal the data with the rule of gbk;

             Deeper reason:

    1 set global character_set_server=utfmb4 just change the global_system_variables, but not the default_charset_info and default_character_set_name.

    2 when handshake, MySQL server writes server characteristics to client, using default_charset_info->number, 28, which is the CharsetIndex of gbk.

    Compare

             As comparison, the steps change to

    1、  set character_set_server= utfmb4 in my.cnf

    2、  insert a data with utf8mb4 characters

    Result: correct data inserted.

             Because the default charset is utfmb4 now, the connector treats dada correctly.

    Discussion

             There are two ways to resolve this problem.

             1 MySQL sends the current character info number in global_system_variables when handshake

             2 Java connector get the correct character to use by “select @@character_set_server;”

    So , is it a bug for MySQL or java-connector?

  • 相关阅读:
    一篇文章高效定位iframe
    URL与视图函数的映射
    include标签—引用文件路径
    UnitTest单元测试框架解析【实用篇】
    【案例演练】测试器与模板继承
    2招带你快速获取响应头与发送头
    dede网站如何更新地图sitemap.html
    申请微信小程序流程步骤
    phpstudy本地配置--dede织梦网
    stylus样式开发的使用----vue
  • 原文地址:https://www.cnblogs.com/kaka100/p/3432133.html
Copyright © 2011-2022 走看看