Two Laptop Bag
The moose likes JDBC and Relational Databases and the fly likes MysqlDataTruncation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "MysqlDataTruncation" Watch "MysqlDataTruncation" New topic


Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 265
Dear Ranchers,
I'm working in JSP and MySQL. the table details of the mysql table is this

When i try to insert the values thru the jsp page.. it is showing error..
the query running behind this is

The error i'm getting is this

What may be the error.. Please help me ranchers!!

Thanks in advance..

Aravind Prasad
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Truncation means shortening. The data type for the field usd_amt is decimal(10,2) which means you can store a floating point number with a maximum of ten digits, of which two can be right of the decimal point. The value you are trying to insert is thei: 1.0305555555555554, so MySQL would have to truncate the number to 1.03 in order to insert it, and that is why you see this exception.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 265
Thankyou Paul Sturrock,
When i tried to insert the query using JSP front end is was showing the error, but when i tried it out using the mysql prompt it was working perfectly and was inserting it like x.yy format. So the problem is with the JSP coding!!
Also when i searched in Google using the error, i got the results like, to change the jdbc connecter.?
is that possible..

Can you please fix for me this problem.

Aravind Prasad
Rama Krishna Ghanta
Ranch Hand

Joined: Nov 20, 2006
Posts: 59
Hi Aravind,

I dont understand how a connector helps you fix this exception. How does a connector help in changing the basic properties of a DATATYPE? The only ways you can fix this is, either change the data type to decimal(10,2) to decimal(somenumber,somebignumber) or Round the decimal value to two digits if your requirement permits.

Rama Krishna Ghanta

I agree. Here's the link:
subject: MysqlDataTruncation
It's not a secret anymore!