This week's book giveaway is in the Kotlin forum. We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line! See this thread for details.
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}]
Set column dataType to LONGTEXT should fix the issue.
Life is but a BREATH
Cezar Apulchro
Ranch Hand
Posts: 76
1
posted 6 months ago
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.
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..
An IDE is no substitute for an Intelligent Developer.
Dave Tolls
Master Rancher
Posts: 3887
45
posted 6 months ago
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: 76
1
posted 6 months ago
Hi Dave,
this is my method cadastrarUltrassonografia:
And this is piece of my bean:
My bean is very long.
Thanks.
Dave Tolls
Master Rancher
Posts: 3887
45
posted 6 months ago
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: 76
1
posted 6 months ago
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.
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.
An IDE is no substitute for an Intelligent Developer.
Dave Tolls
Master Rancher
Posts: 3887
45
posted 6 months ago
1
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: 76
1
posted 6 months ago
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.
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
Programmatically Create PDF Using Free Spire.PDF with Java