This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes problem in deleting data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "problem in deleting data" Watch "problem in deleting data" New topic

problem in deleting data

harsimran kochar

Joined: Sep 09, 2011
Posts: 14
when i click on delete button following exception is generated
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at MyFrame.actionPerformed(

code of my delete button is

and when i use integer.parseint instead of typecasting into integer then i get a error
symbol : method parseInt(java.lang.Object)
location: class java.lang.Integer
int accountno=(Integer.parseInt(mAccthld.getValueAt(tAcctHld.getSelectedRow(),0)));
Paul Clapham

Joined: Oct 14, 2005
Posts: 19687

So the error occurs at this line of code?

And you classify that as a JDBC problem because later in the method there's some JDBC code? Well, anyway, apart from looking in the wrong place for the problem, all that means is that the getValueAt() method doesn't return an Integer object, so you can't cast it to an Integer.

And your proposed fix doesn't compile because getValueAt is declared to return an Object. If you want to use it as a String -- which it is, as you know -- then you need to cast it to String before passing it to the parseInt method.
I agree. Here's the link:
subject: problem in deleting data
It's not a secret anymore!