title: deleting row from JTable and database
body: <p>I want to delete Selected row data from Jtable  and database.</p>
  
  <p>My Code :</p>
  
  <pre><code> try {
  
          DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
          model.removeRow(jTable1.getSelectedRow());
  
          Class.forName("org.sqlite.JDBC");
          Connection con = DriverManager.getConnection("jdbc:sqlite:C:\\management.db");
          Statement st = con.createStatement();
          int id = jTable1.getSelectedRow();
          Object number =  jTable1.getValueAt(id-1,0);
          String sql = "delete  from emp_details where id ="+number;
          int res = st.executeUpdate(sql);
          if(res == 1) {
                  JOptionPane.showMessageDialog(this, "Deleted", "Emp Details", WIDTH);
          }
  
      } catch (ClassNotFoundException ex) {
          Logger.getLogger(Empsearch.class.getName()).log(Level.SEVERE, null, ex);
      } catch (SQLException ex) {
          Logger.getLogger(Empsearch.class.getName()).log(Level.SEVERE, null, ex);
      }
  </code></pre>
  
  <p>When I run the program get the following exception:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -2
  </code></pre>