Message dialog displaying at improper time
<p>I have a searchform. In this I am searching the name alphabetically when I enter the alphabet in textbox and if there is any name from that alphabet in my DB than it shows the message that record found (on click of search button) but when I enter a letter from which there is not any name starting with that letter even than it showing message "record found." </p>

<p>My code is:</p>

<pre><code>if(searchby.equals("Name"))

        {
             try
            {

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            System.out.println("\n Driver loaded");
            Connection con=DriverManager.getConnection("jdbc:odbc:wanisamajDB");

             Statement stmt=con.createStatement();



            ResultSet rs = stmt.executeQuery("SELECT * FROM FAMILYcensus WHERE Name LIKE '"+ tfsearch.getText()+"%'ORDER BY Name ASC");

             StringBuilder sb = new StringBuilder();
             while (rs.next()) {

             String name = rs.getString("Name");
             sb.append(name + System.getProperty("line.separator") );
             }
             String names = sb.toString().trim();


           JOptionPane.showMessageDialog(null, "RECORD FOUND");
           con.close();
           tasearch.setText(names);


           //con.close();

         }
            catch(SQLException eM)
          {
            JOptionPane.showMessageDialog(null,"INVALID RECORD");
           }
          catch(Exception et)
           {
             System.out.println("error:"+et.getMessage());
            }  
</code></pre>
