Data Truncation Error

Last week I was doing some work which needed to import values from CSV file to database. But I got this Data truncation in the middle of the task. When I did a search I found out following details.

Cause: One of the values in CSV file is larger than the allocated size for it in DB.

Solution: I wrote following code to find the maximum length of the values in CSV file.Then increased the allocated size for it in DB.

Code:


result is a double array(String[][]) which contain the values of CSV file.

int count=0;
for(int i=0;i for(int k=0;k int count1 = result[k][i].length();

if(count1>count){count=count1;System.out.println(i+" "+count);}

}
}
System.out.println(count);