title: Problem with return statement
body: <p>I have problem with return statment &gt;.&lt; I want to store all magazine names into</p>
  <pre><code>ArrayList&lt;String&gt; ListNameMagazine = new ArrayList&lt;String&gt;();
  </code></pre>
  <p>I have a DB; in the DB there is a table <code>name_magazine</code> and the data in <code>name_magazine</code> is</p>
  <blockquote>
  <p>Magazine1</p>
  <p>Magazine2</p>
  <p>Magazine3</p>
  <p>Magazine4</p>
  </blockquote>
  <p>This my main:</p>
  <pre><code>    ShowData Show = new ShowData();
  
      int HowManyMagazine = Show.HowManyMagazine(1); // to make sure there is how many Magazine name in my database
  
      //System.out.print(HowManyMagazine); //i want to make sure the data is out.
  
      String nmeMagazine = null; // this variable for get data from return statement 
  
      // i want to store in ListNameMagazine
      ArrayList&lt;String&gt; ListNameMagazine = new ArrayList&lt;String&gt;();
      
      for (int numbeer = 0;numbeer &lt;= HowManyMagazine ; numbeer++)
      {
         //Store in 1 variable String, because if arrayList it's error
          nmeMagazine = Show.getResult(&quot;Select Name_Magazine from Magazine&quot;);
          // Store again in array list
          ListNameMagazine.add(nmeMagazine);
      }
      
      for (String s : ListNameMagazine)
      {
          System.out.println(s); // show the data
      }
  </code></pre>
  <p>This is my return statement:</p>
  <pre><code>public String getResult(String sql)
  throws SQLException
  {
      ResultSet rs = st.executeQuery(sql);
      ResultSetMetaData resultsetmetadata = rs.getMetaData();
  
      //String just_try = null;
      while (rs.next()) { 
           System.out.println(&quot;Result:&quot;+rs.getString(1));
           //just_try = rs.getString(1);
           //return just_try;
      }
      return null;    //return just_try;
  }
  </code></pre>
  <p>The problem is in return statement.</p>
  <p>When the comment ( // ) I erase and the last return null; I delete. It become like here:</p>
  <pre><code>public String getResult(String sql)
  throws SQLException
  {         
       ResultSet rs = st.executeQuery(sql);
       ResultSetMetaData resultsetmetadata = rs.getMetaData();
       String just_try = null;
       
       while (rs.next()) { 
           //System.out.println(&quot;Result:&quot;+rs.getString(1));
          just_try = rs.getString(1);
          return just_try;
       }
  
       return just_try;
   }
  </code></pre>
  <p>When I show the data using this statement.</p>
  <pre><code>for (String s : ListNameMagazine)
      {
          System.out.println(s); // show the data
      }
  </code></pre>
  <p>the result only</p>
  <blockquote>
  <p>Magazine4</p>
  <p>Magazine4</p>
  <p>Magazine4</p>
  <p>Magazine4</p>
  </blockquote>
  <p>@.@ I have confuse where the miss @.@</p>
  <p>but when I show data in return statement like this</p>
  <pre><code>public String getResult(String sql)
  throws SQLException
      {         
      ResultSet rs = st.executeQuery(sql);
      ResultSetMetaData resultsetmetadata = rs.getMetaData();
      String just_try = null;
  
      while (rs.next()) {     
          System.out.println(&quot;Result:&quot;+rs.getString(1));
          //just_try = rs.getString(1);
          //return just_try;
      }
  
      return null;
  }
  </code></pre>
  <p>The data show what I want. I know I only miss in somewhere but I don't know where that @.@. I hope you guys can found it .THX</p>