I have a MySQL table with a Double datatype column, when I insert the value contained in a Java Double I always get a truncation error.
Mrz 19, 2015 11:26:00 AM databaseimport.MyImport executeQuery SCHWERWIEGEND: null java.sql.SQLException: Data truncated for column 'SHARE' at row 1
I tried changing column to a higher precision with DOUBLE PRECISION(30,30) which seems the maximum for the DOUBLE but the error remains.
Here sample snippet:
Double share = (Double) shareRow.get("share");
sql = ("INSERT INTO `SHARE_VALUES` (`ID`, `SHARE`)" +
"VALUES (NULL, "+share+");");
try
{
// Create a Preparedstatement
PreparedStatement ps;
ps = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
ps.execute();
ResultSet generatedKeys = ps.getGeneratedKeys();
}
catch (SQLException ex)
{
java.util.logging.Logger.getLogger(Shares.class
.getName()).log(Level.SEVERE, null, ex);
return -1;
}