I had the same problem When I did this...
String eSql = "";
if (..){
eSql = "select ....";
}
else id (..) {
eSql = "select....";
}
stmt.executeQuery(eSql);
----------
When all the above condition fails eSql = "" and not a valid query and I got that Mandatory error