search

Home  >  Q&A  >  body text

Java - When inserting data with empty value into the database, it says that my data is too long.

When inserting null data into the database, the error message Data truncation: Data too long for column 'REPLY_TYPE' at row 1, this field is set to varchar(20), and the character set of the program and table is utf_8

漂亮男人漂亮男人2787 days ago724

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-25 15:10:09

    Try, jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxxxxx?useUnicode=true&characterEncoding=utf8

    Guarantee: database, tables, fields, program encoding, and jdbc connection are all utf-8

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-25 15:10:09

    I was all in tears. I finally found out. It was because the order of my database fields was inconsistent with the order of insertion in the java code. Long ones were inserted into character types and short ones were restricted.
    insert into table name values ​​(?,?) is a must. The order is consistent with the fields in the table
    insert into table name (field name, field name) values ​​​​(?,?) This order can be inconsistent
    I guess it is only a novice like me who makes this mistake

    reply
    0
  • Cancelreply