title: How to implement database search in JTable if I'm using VOs and DAOs?
body: <p>everyone. I decided to contribute with this topic after racking my brains exhaustively.</p>
  
  <p>Most part of the filtering code I got from:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/11688581/search-a-jtable-repeatedly-using-jtextfield-text">Search a JTable repeatedly using JTextfield text</a></li>
  <li><a href="http://swingdepot.blogspot.com.br/2010/08/text-search-in-jtable.html" rel="nofollow noreferrer">http://swingdepot.blogspot.com.br/2010/08/text-search-in-jtable.html</a></li>
  </ul>
  
  <p>Software used:</p>
  
  <ul>
  <li>MySQL 14.14</li>
  <li>JDK 7</li>
  <li>NetBeans 7.1.2</li>
  </ul>
  
  <p>Suppose we have the following example table called "<strong>table</strong>":</p>
  
  <pre><code>+-----------+-------------+------+-----+---------+----------------+
  | Field     | Type        | Null | Key | Default | Extra          |
  +-----------+-------------+------+-----+---------+----------------+
  | id        | int(11)     | NO   | PRI | NULL    | auto_increment |
  | name      | varchar(50) | YES  |     | NULL    |                |
  | phone     | varchar(20) | YES  |     | NULL    |                |
  | birthdate | datetime    | YES  |     | NULL    |                |
  | status    | int(1)      | YES  |     | NULL    |                |
  +-----------+-------------+------+-----+---------+----------------+
  </code></pre>
  
  <p>Creating a view called "<strong>vTable</strong>", considering a list that will display only the ID, the name and the birth date:</p>
  
  <pre><code>CREATE VIEW vTable AS
  SELECT id, name, birthdate FROM table WHERE status IS NOT NULL;
  </code></pre>
  
  <p>I'm using MVC pattern, so there are packages "model", "view" and "controller".</p>
  
  <p>Creating the data access object <strong>TableDAO</strong>:</p>
  
  <pre><code>package model.DAO;
  
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Vector;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import model.VO.TableDAO;
  import model.VO.VTableVO;
  
  public class TableDAO extends ConnectionDAO {
  
      public List&lt;VInstituicaoVO&gt; List() throws ClassNotFoundException {
  
          List&lt;VTableVO&gt; listTable = new ArrayList&lt;&gt;();
          try {
              openConnection();
              con.setAutoCommit(false);
              PreparedStatement stmt = con.prepareCall(
                      "SELECT id, name, birthdate FROM vTable");
              ResultSet record = stmt.executeQuery();
  
              while(record.next()) {
                 VTableVO  vo = new VTableVO();
                 vo.setId(record.getInt(1));
                 vo.setName(record.getString(2));
                 vo.setBirthdate(record.getDate(3));
                 listTable.add(vo);
              }
  
              closeConnection();
  
          } catch (SQLException ex) {
              Logger.getLogger(TableDAO.class.getName()).log(Level.SEVERE, null, ex);
          }
          return listTable;
  }
  </code></pre>
  
  <p>Creating the value-object (don't forget to generate getters and setters) <strong>TableVO</strong>:</p>
  
  <pre><code>package model.VO;
  
  import java.sql.Date;
  
  public class TableVO {
  
      private Integer id;
      private String name;
      private String phone;
      private Date birthdate;
      private int status;
  
      public TableVO() {}
  
      public TableVO(ITableVO vo) {
  
          id = vo.getId();
          name = vo.getName();
          phone = vo.getPhone();
          birthdate = vo.getBirthdate();
          status = vo.getStatus();
  
      }
  
     // GENERATE GETTERS AND SETTERS
  
  }
  </code></pre>
  
  <p><strong>VTableVO</strong> class:</p>
  
  <pre><code>package model.VO;
  
  import java.sql.Date;
  
  public class VTableVO {
  
      private Integer id;
      private String name;
      private Date birthdate;
  
  // GENERATE GETTERS AND SETTERS
  
  }
  </code></pre>
  
  <p><strong>ITableDAO</strong> interface:</p>
  
  <pre><code>package model.DAO;
  
  import java.util.List;
  import model.VO.TableVO;
  
  public interface ITableDAO {
  
      public List&lt;TableVO&gt; List();
  
  }
  </code></pre>
  
  <p><strong>ITableVO</strong> interface:</p>
  
  <pre><code>package model.VO;
  
  import java.sql.Date;
  
  public interface ITableVO {
  
      public Integer getId();
      public void setId(Integer set_id);
  
      public String getName();
      public void setName(String set_nome);
  
      public String getPhone();
      public void setPhone(String set_phone);
  
      public Date getBirthdate();
      public void setBirthdate(Date set_birthdate);
  
      public Integer getStatus();
      public void setStatus(Integer set_status);
  
  }
  </code></pre>
  
  <p>With this structure, how could we implement a search function in a JTable?</p>