Data truncation: Data too long for column 'logo' at row 1

前端 未结 3 1503
难免孤独
难免孤独 2020-12-05 01:41

I am trying to insert a photo into a BLOB column of a MySQL table, and I get an exception:

Data too long for column \'logo\' at row 1. 

Her

相关标签:
3条回答
  • 2020-12-05 02:16

    Use data type LONGBLOB instead of BLOB in your database table.

    0 讨论(0)
  • 2020-12-05 02:31

    You are trying to insert data that is larger than allowed for the column logo.

    Use following data types as per your need

    TINYBLOB   :     maximum length of 255 bytes  
    BLOB       :     maximum length of 65,535 bytes  
    MEDIUMBLOB :     maximum length of 16,777,215 bytes  
    LONGBLOB   :     maximum length of 4,294,967,295 bytes  
    

    Use LONGBLOB to avoid this exception.

    0 讨论(0)
  • 2020-12-05 02:33

    Following solution worked for me. When connecting to the db, specify that data should be truncated if they are too long (jdbcCompliantTruncation). My link looks like this:

    jdbc:mysql://SERVER:PORT_NO/SCHEMA?sessionVariables=sql_mode='NO_ENGINE_SUBSTITUTION'&jdbcCompliantTruncation=false
    

    If you increase the size of the strings, you may face the same problem in future if the string you are attempting to store into the DB is longer than the new size.

    EDIT: STRICT_TRANS_TABLES has to be removed from sql_mode as well.

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