com.mysql.jdbc.MysqlDataTruncation:データの切り捨て:切り捨てられた誤ったDOUBLE値



Com Mysql Jdbc Mysqldatatruncation



com.mysql.jdbc.MysqlDataTruncation:データの切り捨て:SQLの実行時に切り捨てられた誤ったDOUBLE値エラーが表示されます:
このエラーは、主に次の操作などの操作で発生します。

#hibernate update tablename set status=1 where id in (:ID) #jdbc update tablename set status=1 where id in (?); #mybatis update tablename set status=1 where id in#{ID})

ID値が1、2、3に類似している場合、エラーが報告されます。



com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value'1,2,3'

その理由は、この置換方法は、値が渡されるときに1、2、3を直接渡し、次に対応するタイプに変換するためです。

解決:



#1, direct splicing SQL 'update tablename set status=1 where id in (' + idStr + ')' #2. Use the protection mechanism of skipping jdbc with direct replacement. The key point is to let jdbc directly replace with the value you pass in without other processing. update tablename set status=1 where id in (::ID) update tablename set status=1 where id in (${ID}) #3, use the list splicing operation of the orm framework, such as the foreach tag of mybatis