Failing to delete, edit from resultset

Please help me gurus, I am failing to insert and delete resultset data from ms access database. Invalid cursor state is given when I try to run delete button.
class Application
{ public static void main(String argv[])
  { Application dummy = new Application();
//Instance variables
  private GUI gui;
import javax.swing.table.*;
import java.sql.*;
import java.util.*;
import java.lang.Exception;
import javax.swing.*;
class Model extends AbstractTableModel
  //Variables/constants for model
  private Application application;
  Connection con;
  Statement stmt;
  //PreparedStatement pstmt;
  ResultSet rs;
  ResultSetMetaData rmd;
  List rows = new ArrayList();
  List columnNames = new ArrayList();
  List dummy;
  //Constructor
  public Model(Application a)
    { application = a;
  //public Model()
  { try
    { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(ClassNotFoundException e){System.out.println(e.getMessage());}
    try
    { con = DriverManager.getConnection("jdbc:odbc:jdbcExample");
      stmt = con.createStatement();
      rs = stmt.executeQuery("SELECT * FROM birthdays ");
      rmd = rs.getMetaData();
      for (int i = 1; i <= rmd.getColumnCount();i++)
      { columnNames.add((String)rmd.getColumnName(i));
      while(rs.next())
      { List cols = new ArrayList();
        for(int col = 1; col <= columnNames.size(); col++)
        { cols.add(rs.getString(col));
        rows.add(cols);
    catch(SQLException e){System.out.println(e);}
  //public instance methods for AbstractTableModel
  public int getRowCount()
  { return rows.size();
  public int getColumnCount()
  { dummy = (List)rows.get(0);
    return dummy.size();
  public Object getValueAt(int row, int col)
  { dummy = (List)rows.get(row);
    return dummy.get(col);
  public String getColumnName(int col)
  { return (String)columnNames.get(col);
  public void newPerson() {
     //Connection con = DriverManager.getConnection
     try {
               ResultSet rs = stmt.executeQuery
               ("SELECT * FROM birthdays WHERE familyName LIKE '%ro%' ");
           while (rs.next())
           { String entry = rs.getString("givenName") +
             rs.getString("familyName") +
        rs.getString("birthday");
     } catch( SQLException se ) { System.out.println( se ); }
     public void deletePerson()
     try{
     rs.deleteRow() ;//throws SQLException;
          catch( SQLException se ) { System.out.println( se ); }
          Application dummy= new Application();
     public void addText(int column,int row){
     public void givenNameSort(){
          try {
          ResultSet rs = stmt.executeQuery
                         ("SELECT givenName FROM birthdays");
     catch( SQLException se ) { System.out.println( se ); }
     public void lastNameSort(){
     try {
     ResultSet rs = stmt.executeQuery
                                   ("SELECT * FROM birthdays order by givenName");
     catch( SQLException se ) { System.out.println( se ); }
     public void dateOfBirthSort(){
          try {
     ResultSet rs = stmt.executeQuery
                              ("SELECT * FROM birthdays WHERE familyName order by to_date(givenname,'MMYY' ");
     catch( SQLException se ) { System.out.println( se ); }
     public void saveChanges(){
  private Model model;
// Constructor
  public Application()
    model = new Model(this);
     gui = new GUI(this);
//Interface methods
  public void newPerson()
  { model.newPerson();
  public void deletePerson()
  { model.deletePerson();
  public void editPerson(int column,int row)
  { model.addText(column,row);
  public void givenNameSort()
  { model.givenNameSort();
  public void lastNameSort()
  { model.lastNameSort();
  public Model getModel() {
       return model;
  public void dateOfBirthSort()
  { model.dateOfBirthSort();
  public void saveChanges()
  { model.saveChanges();
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class GUI
//Instance variables
  private Application application;
  private Model model;
//GUI components
  private JButton helpButton = new JButton("Help");
  private JButton newPersonButton = new JButton("New Person");
  private JButton deletePersonButton = new JButton("Delete Person");
  private JButton editPersonButton = new JButton("Edit Person");
  private JButton givenNameSortButton = new JButton("Sort Givename");
  private JButton lastNameSortButton = new JButton("Sort Lastname");
  private JButton dateOfBirthSortButton = new JButton("Sort MoB");
  private JButton saveChangesButton = new JButton("Save Changes");
  private JTextField givenNameTF   = new JTextField(12);
  private JTextField lastNameTF    = new JTextField(6);
  private JTextField addressTF        = new JTextField(20);
  private JLabel wordCountLabel = new JLabel("Word count: 0");
  //private JTextArea wordList = new JTextArea(
  //private JTable dbTable = new JTable(Model());
     private JTable dbTable;
//Panels, Panes and Boxes
  private Box mainBox    = new Box(BoxLayout.X_AXIS);
  private Box controlBox = new Box(BoxLayout.Y_AXIS);
  //private Panel inputBox = new Panel();
  //private JScrollPane scrollingWordList; // to make wordList scroll
  private JScrollPane scrollTable;
//Window.
  private JFrame frame = new JFrame("JTable and TableModel");
  private Container pane = frame.getContentPane();
//Constructor
  public GUI( Application a)
  { this.application = a;
     dbTable = new JTable( application.getModel() );
       scrollTable = new JScrollPane(dbTable,
      JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
      JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    pane.add(scrollTable);
//   pane.add(inputBox);
    controlBox.add(new JLabel(" "));
    //inputBox.setLayout(new GridLayout(4, 2));
         controlBox.add(helpButton);
         controlBox.add(new JLabel(" "));
         controlBox.add(newPersonButton);
         controlBox.add(deletePersonButton);
         controlBox.add(new JLabel(" "));
         controlBox.add(editPersonButton);
         controlBox.add(new JLabel(" "));
      //   controlBox.add(wordCountLabel);
         controlBox.add(new JLabel(" "));
         controlBox.add(givenNameSortButton);
         controlBox.add(lastNameSortButton);
         controlBox.add(dateOfBirthSortButton);
         controlBox.add(new JLabel(" "));
         controlBox.add(saveChangesButton);
         controlBox.add(new JLabel(" "));
//         inputBox.add(givenNameTF);
//         inputBox.add(lastNameTF);
//         inputBox.add(addressTF);
         newPersonButton.addActionListener(new NewPersonButtonListener());
      frame.addWindowListener(new WindowClose());
         helpButton.addActionListener(new HelpButtonListener());*/
          deletePersonButton.addActionListener(new DeletePersonButtonListener());
          editPersonButton.addActionListener(new EditPersonButtonListener());
          givenNameSortButton.addActionListener(new GivenNameSortButtonListener());
          lastNameSortButton.addActionListener(new LastNameSortButtonListener());
          dateOfBirthSortButton.addActionListener(new DateOfBirthSortButtonListener());
          saveChangesButton.addActionListener(new SaveChangesButtonListener());
    mainBox.add(controlBox);
    mainBox.add(scrollTable);
//     mainBox.add(inputBox);
    pane.add(mainBox);
    frame.addWindowListener(new FrameListener());
    frame.setLocation(100, 100);
    frame.setSize(300, 150);
    frame.setResizable(true);
    frame.setVisible(true);
    frame.pack();
//Instance methods
//Listeners
  class FrameListener extends WindowAdapter
  { public void windowClosing(WindowEvent evt)
    { System.exit(0);
    class NewPersonButtonListener implements ActionListener
    { public void actionPerformed(ActionEvent evt)
      { application.newPerson();
    class DeletePersonButtonListener implements ActionListener
         { public void actionPerformed(ActionEvent evt)
           { application.deletePerson();
    class EditPersonButtonListener implements ActionListener
              { public void actionPerformed(ActionEvent evt)
                { application.editPerson(1,1);
    class GivenNameSortButtonListener implements ActionListener
              { public void actionPerformed(ActionEvent evt)
                { application.givenNameSort();
    class LastNameSortButtonListener implements ActionListener
              { public void actionPerformed(ActionEvent evt)
                { application.lastNameSort();
    class DateOfBirthSortButtonListener implements ActionListener
              { public void actionPerformed(ActionEvent evt)
                { application.dateOfBirthSort();
    class SaveChangesButtonListener implements ActionListener
              { public void actionPerformed(ActionEvent evt)
                { application.saveChanges();
  }

My observations:
* I cannot see your resultset being declared as updatable anywhere.
* You should print out the stack trace while developing an application. It is usually more informative than just printing the exception message.
* Your JDBC resources are not being handled properly.
The first observation pertains to the problem at hand, I suppose.

Similar Messages

Maybe you are looking for