• 修改mysql数据的字符集


    今天遇到了一个异常,在插入数据库的时候报错,报错内容如下:

    ### Error updating database.  Cause: java.sql.SQLException: Incorrect string value: '\xE5\x8F\xA3\xE7\x81\xAB...' for column 'name' at row 1
    ### The error may exist in com/cashway/record/mapper/BusinessMapper.java (best guess)
    ### The error may involve com.cashway.record.mapper.BusinessMapper.insert-Inline
    ### The error occurred while setting parameters
    ### SQL: INSERT INTO tb_business  ( id, pid, name,  created_by, created_time, updated_by, updated_time )  VALUES  ( ?, ?, ?,  ?, ?, ?, ? )
    ### Cause: java.sql.SQLException: Incorrect string value: '\xE5\x8F\xA3\xE7\x81\xAB...' for column 'name' at row 1
    ; uncategorized SQLException; SQL state [HY000]; error code [1366]; Incorrect string value: '\xE5\x8F\xA3\xE7\x81\xAB...' for column 'name' at row 1; nested exception is java.sql.SQLException: Incorrect string value: '\xE5\x8F\xA3\xE7\x81\xAB...' for column 'name' at row 1
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89) ~[spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
        at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.1.6.RELEASE.jar:5.1.6.RELEASE]
        at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91) ~[mybatis-spring-2.0.6.jar:2.0.6]

    查了一波是说数据库字符集有问题,所以在保存中文内容的时候会报错,需要改数据库的字符集,于是便有了下面这句,修改数据库的字符集。

    alter database 数据库名 character set utf8;

  • 相关阅读:
    【JavaScript 进阶教程】汽车商城根据价格区间筛选车辆案例
    MongoDB——centOS7环境Mongodb权限管理(图解版)
    Python-函数传参与数据类型
    (十三)强缓存和协商缓存的区别
    数据结构算法-分而治之算法
    pyclipper和ClipperLib操作多边型
    【Python】Windows跟随程序启动和关闭系统代理
    高效工作必备:测试人如何提高沟通技能?
    前端需要了解的linux命令
    7 个不容忽视的开源安全工具
  • 原文地址:https://blog.csdn.net/lp840312696/article/details/126544348