Results 1 to 2 of 2
  1. #1
    harsimran05 is offline Member
    Join Date
    Sep 2011
    Posts
    6
    Rep Power
    0

    Default problem in deleting data

    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

    Java Code:
    if(o.equals(bDelete)){   
                    try {   
                     int accountno=(Integer)mAccthld.getValueAt(tAcctHld.getSelectedRow(),0);   
                        mAccthld.removeRow(tAcctHld.getSelectedRow());   
                           
                            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");   
         Connection con=DriverManager.getConnection("jdbc:odbc:DRIVER=Microsoft Access DRIVER (*.mdb);DBQ=fddata.mdb");   
    PreparedStatement ps=con.prepareStatement("delete from accthld where AccountNo=?");   
                            ps.setInt(1,accountno);   
                            int s=ps.executeUpdate();   
                            System.out.println(s);   
                            con.close();   
                    }   
                    catch(Exception ex){   
                        ex.printStackTrace();   
                    }   
                                
                       
                }
    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(tA cctHld.getSelectedRow(),0)));
    ^

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: problem in deleting data

    I presume mAccthld is a JTable? Cast the returned value of getValueAt to a String, then use Integer.parseInt to get the int value.

Similar Threads

  1. Problem with deleting record.
    By javaguy345 in forum JDBC
    Replies: 18
    Last Post: 05-21-2011, 02:37 AM
  2. String problem: deleting
    By BlueBird in forum New To Java
    Replies: 3
    Last Post: 03-18-2011, 05:21 AM
  3. Replies: 7
    Last Post: 02-10-2011, 07:37 PM
  4. deleting the data in the column model
    By bigj in forum New To Java
    Replies: 0
    Last Post: 02-08-2010, 08:15 AM
  5. Vector/Table Deleting Row Problem.
    By ocean in forum New To Java
    Replies: 8
    Last Post: 12-09-2009, 06:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •