com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value:

This error may crop up if you are doing any DML operation through IN clause.
Example
String sql = 'update table set status = true where id in (?)'

If you are using the above statement as part of the prepared statement and the 'id' column is of long type. Following would give this error.
String str = "1,2,3,4";

PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, str);
stmt.executeUpdate();

The last line would give the error.
Reason being that the column is of Long(BIGINT) type and value is passed as string.
You cannot say
stmt.setLong(1, str);
as the 'str' contains comma separated values.
One of the solution in this case is to create separate place holders for each input value
String sql = 'update table set status = true where id in (?,?,?,?)'
in this case and pass individual long values to the statement object.

Other options are welcome.

Comments

Popular posts from this blog

Hibernate: a different object with the same identifier value was already associated with the session

BeanDefinitionStoreException: Failed to parse configuration class: Could not find class [javax.jms.ConnectionFactory]