cofactor
asked on
ClassCastException
I'm trying to send multiple textarea values from jsp to be inserted into database. However the textarea values are not received in the Action class properly. I get ClassCastException when trying to insert the data into database.
Whats the workaround ?
Please see the file attached for details
ClassCastException.txt
Whats the workaround ?
Please see the file attached for details
ClassCastException.txt
Y ur casting that in to string ?
ASKER
>>>Y ur casting that in to string ?
If I dont do , then I get compile error
in java.sql.PreparedStatement
[javac] ps.setString(3,cvo.getItem
ASKER
>>>It looks like you are trying to cast array of Strings into String. Try casting to Stirng[].
please see the prints I put in the attached text file.
My objective is, I want to get the String values entered in the textarea and insert into database. What would be the correct code ?
please see the prints I put in the attached text file.
My objective is, I want to get the String values entered in the textarea and insert into database. What would be the correct code ?
try with toString() method
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Where you call this:
You should actually call:
where i is the index of your text item.
(String)cvo.getItemDescription()
You should actually call:
((String[])cvo.getItemDescription())[i]
where i is the index of your text item.
ASKER
object is right . That works . Awesome!
I just put the generic as object suggested and the error vanished....excellent.
But why the explicit casting did not work ? Why the generic worked but explicit cast failed ?
I'm using jdk 1.6 .
I just put the generic as object suggested and the error vanished....excellent.
But why the explicit casting did not work ? Why the generic worked but explicit cast failed ?
I'm using jdk 1.6 .
> But why the explicit casting did not work ? Why the generic worked but explicit cast failed ?
because it wasn't a list of strings.
Without the generics it cannot accurately determine what the type of object in the list is
because it wasn't a list of strings.
Without the generics it cannot accurately determine what the type of object in the list is
It looks like you are trying to cast array of Strings into String. Try casting to Stirng[].