When I run the following the below sql statement from sqlyog it works OK but when I run it from my java application I receive exception.
With other queries I don't have this problem.
What can cause this ?

The query:
create temporary table TempTable1 SELECT salaries.salary AS `salary`,salaries.emp_no AS `emp_no`,salaries.from_date AS `from_date`,MAX(salaries.salary) AS `func` FROM `salaries` WHERE salaries.to_date = '9999-01-01'

The exception:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraint ViolationException: Column 'salary' cannot be null