title: how to retrieve data from database correctly in java
body: <p>I wrote this code in order to display the name of employee who has the maximum salary 
  but when the output wasn't correct it appeared null not "mmm kkk" !! although I filled the table and this is the contents :</p>
  
  <p><a href="https://dl.dropboxusercontent.com/u/108513041/Screenshot%20from%202013-06-19%2012:20:05.png" rel="nofollow">HERE</a></p>
  
  <p>this is my code, can any one help me ?? :(</p>
  
  <pre><code> public static void displayMaxSalary() throws ClassNotFoundException, SQLException
  
  {   
      int size=0;
      int count=0;
      String maxSalary=null;
      Class.forName("com.mysql.jdbc.Driver");
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost/task4DB?"
                + "user=root&amp;password=123");
      PreparedStatement st = con.prepareStatement("select * from task4Table ");
      ResultSet r1=st.executeQuery();
  
        while (r1.next()) {
  
            size++;
        }
  
  
        int salaries[]=new int[size];
        String Names[]=new String[size];
  
         while (r1.next()) {
  
  
            salaries[count]= r1.getInt("salary");
            Names[count]=  r1.getString("fName")+""+r1.getString("lName");
            count++;
        }
  
         for(int i=1;i&lt; salaries.length;i++)
  
         {
             if(salaries[i]&gt;salaries[i-1])
             {
                 maxSalary= Names[i];
             }
  
         }
  
  
       System.out.println("The name of employee who has the higher salary is :");
       System.out.println( maxSalary);
  
  
  
  } //end-displayMaxSalary.
  </code></pre>