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 :

HERE

this is my code, can any one help me ?? :(

 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.



Question: Variable scope in while-read-loop on Solaris
Answer: In the Bourne shell, redirecting a compound command (like your while loop) runs that compound command in a subshell.

In Solaris 10 and earlier1, you don't want to use /bin/sh as it's the Bourne shell. Use /usr/xpg4/bin/sh or /usr/bin/ksh instead to get a POSIX sh.

If for some reason you have to use /bin/sh, then to work around that, instead of doing:

compound-command &lt; file


You can do:

exec 3&lt;&amp;0 &lt; file
compound-command
exec &lt;&amp;3 3&lt;&amp;-


That is:


duplicate the fd 0 onto fd 3 to save it away and then redirect fd 0 to the file. 
run the command
restore fd 0 from the saved copy on fd 3. And close fd 3 which is no longer needed.




1. In Solaris 11 and later, Oracle eventually (at long last) made /bin/sh a POSIX shell, so it now behaves like the sh of most other Unices (it interprets the sh language specified by POSIX though it supports extensions over it as it's based on ksh88 (like other Unices, where sh is now generally based on ksh88, pdksh, bash, yash or an enhanced ash))