How to silently truncate strings while storing them when they are longer than the column length definition?

前端 未结 12 1388
梦谈多话
梦谈多话 2020-12-24 06:17

I have a web app, using EclipseLink and MySQL for storing data. Some of these data are strings, ie varchars in the DB. In the code of entities, the strings have attributes

12条回答
  •  误落风尘
    2020-12-24 06:33

    There is another way to do it, may be even faster (at least it works on 5th version of MySql):

    First, check your sql_mode setting: there is a detailed description how to do it. This setting should have value of "" for windows, and "modes" for Unix.

    That didn't help me, so I found another setting, this time in jdbc:

    jdbcCompliantTruncation=false. 
    

    In my case (I used persistence) it is defined in persistence.xml:

    
    

    These 2 settings work only together, I tried to use them separately and had no effect.

    Notice: remember that by setting sql_mode as described above you switch off important database checks, so please do it carefully.

提交回复
热议问题