首页 > 解决方案 > springboot java mysql参数出现语法错误

问题描述

我有这个应用程序,java spring boot 和 mysql db。当我尝试运行以下查询时,我收到此错误。 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 'email ='rahul@gmail.com.com'' at line 1

有谁知道为什么?

    @Query(value = "SELECT voucher_code FROM voucher INNER JOIN "
        + "offer ON offer.name = voucher.offer "
        + " email =:email", nativeQuery = true)
     List<Voucher> getVouchers(@Param("email") String email);

标签: javamysqlspring-boot

解决方案


您在这两个条件之间缺少一些东西offer.name = voucher.offeremail =:email可能是一个WHERE,也许是一个AND/OR。我猜你想要这个:

@Query(value = "SELECT voucher_code FROM voucher INNER JOIN "
    + "offer ON offer.name = voucher.offer "
    + "WHERE email =:email", nativeQuery = true)
List<Voucher> getVouchers(@Param("email") String email);

推荐阅读