java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by vendordesc' at line 1 Query is: SELECT vendoradd1,vendoradd2,vendorzip,vendorlogo,vendorteleno,vendorurl,vendordesc,venabout,vendorimage,CardId FROM vendor left join advantagecard on vendorcode=Cardcode and cardactive='Y' and ( Date_format(now(),'%Y/%m/%d %T')>=Date_format(cardStartDate,'%Y/%m/%d %T') and Date_format(now(),'%Y/%m/%d %T')<=Date_format(cardEndDate,'%Y/%m/%d %T') ) where dirrefno= order by vendordesc