Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.sql.SQLException: Data truncated for column 'MonthlyIncome' at row 1 error

Tags:

java

sql

I am trying to update as well as save data to my database using my GUI. My problem is, if i don't enter any data to certain textboxes which i have allowed null on my database, i get this kind of error: java.sql.SQLException: Data truncated for column 'MonthlyIncome' at row 1

like image 612
zairahCS Avatar asked Mar 06 '12 16:03

zairahCS


3 Answers

Typically this problem occurs when you are putting in a data that is too long for the column. In this case, whatever data you are updating the 'MonthlyIncome' field with is too long.

like image 199
FAtBalloon Avatar answered Nov 15 '22 16:11

FAtBalloon


Another reason why this error could occur is when the type of your column is an ENUM with a limited list of values but you are trying to insert something that doesnt belong in that list.

For instance, if your column type is ENUM ('XXX','YYY','ZZZ') but you are trying to insert a value 'AAA' into this column, you'll get the same error.

like image 13
Dhrupadh Avatar answered Nov 15 '22 17:11

Dhrupadh


If you are using Hibernate, then another reason might be you're missing @Enumerated annotation. Annotate it with your desired data type like the example below :

@Column(name="monthly_income")
@Enumerated(EnumType.STRING)
private MonthlyIncome monthlyIncome
like image 1
Niloy Rashid Avatar answered Nov 15 '22 17:11

Niloy Rashid