title: Deleting selected row in MySQL database through JTable
body: <ul>
  <li>tb_records = jtable name </li>
  <li>records = table name inside my database </li>
  <li>Date = my first column </li>
  <li>hey = substitute for my real password </li>
  <li>mydatabase = name of my database</li>
  </ul>
  
  <p>My problem is that, when I highlight a row in my JTable and delete it, it deletes all the rows. I want to delete the selected row only. Here's my code:</p>
  
  <pre><code>int row = tb_records.getSelectedRow();
  DefaultTableModel model= (DefaultTableModel)tb_records.getModel();
  
  String selected = model.getValueAt(row, 0).toString();
  
              if (row &gt;= 0) {
  
                  model.removeRow(row);
  
                  try {
                      Connection conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase", "root", "hey");
                      PreparedStatement ps = conn.prepareStatement("delete from records where Date='"+selected+"' ");
                      ps.executeUpdate();
                  }
                  catch (Exception w) {
                      JOptionPane.showMessageDialog(this, "Connection Error!");
                  }           
              }
  </code></pre>
  
  <p>What could be the problem here? How can I delete a selected row in my database and not all the rows?</p>