title: SQL Query for a search function
body: <p>I want to do a Search function with multiple Java Swing components, where a user can search by (name/nationality/specialty/experience) and results will be displayed in a Jtable.</p>
  
  <p><a href="https://i.stack.imgur.com/yiRdM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yiRdM.png" alt="enter image description here"></a></p>
  
  <p>I'm only struggling with the SQL Query, as if a user typed a 'name' only, no data will be retrieved because it goes to database like this (name, null, null, null) and I don't have any null values in my database.</p>
  
  <p>So I want to retrieve all data with that name regardless of other columns, but at the same time, if they also chose a specific specialty for example, I want to retrieve all data with the selected name AND specialty, and so on.</p>
  
  <p>I hope you understand my question.</p>
  
  <p>My current SQL statement:</p>
  
  <pre><code>public ArrayList&lt;Applications&gt; getData(String name, String nationality, String specialty, String experience) {
  
     ArrayList&lt;Applications&gt; list = new ArrayList&lt;Applications&gt;();
     Connection con = getConnection();
     Statement st;
     ResultSet rows;
  
     try {
         st = con.createStatement();
  
         rows = st.executeQuery("SELECT * FROM applications WHERE name LIKE '%" +  name+"%'"
              + " AND (nationality LIKE '" +  nationality+"')"
              + " AND (specialty LIKE '" +  specialty+"')"
              + " AND (experience LIKE '" +  experience+"')");
  
         Applications applications;
  
         while(rows.next()) {
             applications = new Applications(
                 rows.getInt("id"),
                 rows.getString("name"),
                 rows.getString("nationality"),
                 rows.getString("Specialty"),
                 rows.getString("experience")
             );
  
            list.add(applications);
         }   
     } catch (SQLException ex) {
         Logger.getLogger(MyQuery.class.getName()).log(Level.SEVERE, null, ex);
     }
  
     return list;
  }
  </code></pre>