Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Data truncation: Data too long for column  RSS feed

 
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

more one problem for yours. I have this DAO that I want to return the code of an item, the return are ok but the problem is that when I get the code returned to write in my db, the message is data too long.

My DAO:


And this is my access:



The line 28 is to know the code returned, this is the result of the disply:

Codigo antes de gravar: [Bean_Procedimentos_Ultra{CNES=null, Procedimentos=null, Codigo=004}, Bean_Procedimentos_Ultra{CNES=null, Procedimentos=null, Codigo=004}]

My problem is that I can´t access the "Codigo".

Can you help me?

Thanks in advance.

Cezar Apulchro.
 
Rancher
Posts: 3595
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we need a bit more information.
What is the full error you are getting, and where is it occurring?

Do you know the value that is giving that error?
If the value is incorrect, what should the value be?

 
Saloon Keeper
Posts: 4683
117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also post the description (column names and types) of the Tabela_Procedimentos_Ultrassonografia table.
 
Ranch Hand
Posts: 81
1
Android Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set column dataType to LONGTEXT should fix the issue.
 
Cezar Apulchro
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,
thank you for assistance.

This is my table:


This is the content of my table:


And the full error:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'Codigo_Procedimentos' at row 1

The error occur  in line 31(pcdao.cadastrarUltrassonografia(dpaciente);) I believe caused by line 29(dpaciente.setCodigo_Procedimento(codprocedimentos);).
The result of this dysplay:


Is:
Codigo antes de gravar: [Bean_Procedimentos_Ultra{CNES=null, Procedimentos=null, Codigo=004}, Bean_Procedimentos_Ultra{CNES=null, Procedimentos=null, Codigo=004}]

CNES, Procedimentos and Codigo, are columns of my table and of my Bean. Note in this dysplay Codigo=004, the content of Codigo are ok, my problem is that I can't access this content in return of my Select.

Thanks.
 
Bartender
Posts: 19657
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's extra challenging when not only the object, property and method names are not in English, but so are the error messages!

It appears that you have a fault in your registration method (cadastrarUltrassonografia), but unless I'm just blind today, you didn't show us what the PacientesDAO_W01 class that defines it looks like, so we have no idea what it's expecting.

The error message looks possibly like you have 2 patient records in it, and you're attempting to force them into a single database field - multiple columns AND multiple rows!

But that is only my best attempt at divination..
 
Dave Tolls
Rancher
Posts: 3595
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Data too long for column 'Codigo_Procedimentos'

That is not a column of the table you posted.

It looks like this is an error (as Tim says) from another method, not the one you have already posted.
From the stack trace is would be the cadastrarUltrassonografia method.
 
Cezar Apulchro
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,

this is my method cadastrarUltrassonografia:


And this is piece of my bean:


My bean is very long.

Thanks.
 
Dave Tolls
Rancher
Posts: 3595
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Now, based on your first post, the value being used here is:
"
[Bean_Procedimentos_Ultra{CNES=null, Procedimentos=null, Codigo=004}, Bean_Procedimentos_Ultra{CNES=null, Procedimentos=null, Codigo=004}]
"
which has come from using the codprocedimentos String in the call to setCodigo_Procedimento.
And that String comes from:


And lbultra is a List.

So, the question is, what exactly is supposed to be supplied to setCodigo_Procedimento?
What is it you actually want to go in there?

If it is (as it sounds like) the value of Codigo from that String, then which Codigo, as there are two (which happen to be the same in this example).
 
Cezar Apulchro
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave I don't understand what you mean, I have an table with 3 collumns, I use only collumn 'Procedimentos' to populate a box to user choice in my jsp page. I get the user option and I want to get the code 'Codigo' of that option in my table. I have constructed another method but the problem still the same.

This method was constructed first, but has same problem, then I cosntructed the 'lstCodUltra' method.

Thanks.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to increase the size of your table column.
 
Tim Holloway
Bartender
Posts: 19657
92
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are leaking resources. If you get a SQLException, it causes the PreparedStatement.close() method to be bypassed.

What it looks like is that instead of sending the value of the Codigo_Procedimento - which appears to be a class instance, not a simple value - to the SQL preparer you are sending the value of the Codigo_Procedimento.toString() method, which is much longer than the actual data value, since it contains additional information about the Codigo_Procedimento which appears to be not a single value, but an entire class.

SQL isn't designed to stuff multiple objects into a single column. So you have to select an alternative:

1. Put the data into multiple columns, one column per data element
2. Encode the data into a single value (for example a String or serialized Java) and store it into a column large enough to hold it.
3. Write the data into a separate and distinct table and have your primary data reference that data (via a foreign key).

What it looks like you are attempting is option 2 but without a large enough column. Aside from needing enough space to hold the data, you'd also need a corresponding decode (deserialize) operation when you read the data back. And while I mentioned Java serialization as an alternate format, I don't recommend using it, because different JVM versions do it differently so you might not be able to deserialize it later.
 
Dave Tolls
Rancher
Posts: 3595
39
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Cezar Apulchro wrote:Dave I don't understand what you mean...



OK.

According to your second post above you are getting the error:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'Codigo_Procedimentos' at row 1

That highlighted name is the column causing the issue.
That column is populated by the PreparedStatement code you posted just above here.
And this is the line that does that:


So your problem is that the value supplied there (which, if we work back up the code, comes from that toString call) is incorrect.

I am trying to find out what it should be.
 
Cezar Apulchro
Ranch Hand
Posts: 37
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I solved my problem "Data truncation: Data too long for column".

Solution:

in mysql table: codigo varchar changed to int

in bean: I changed String to int


thanks a lot everybody.

Cezar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!