wood burning stoves 2.0*
The moose likes JDBC and the fly likes problem in deleting data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "problem in deleting data" Watch "problem in deleting data" New topic
Author

problem in deleting data

harsimran kochar
Greenhorn

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(AcctHld.java:226)

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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
 
GeeCON Prague 2014
 
subject: problem in deleting data