Rahul SK
Rahul SK

Reputation: 422

springboot java mysql syntax error at parameter

I have this application, java spring boot and mysql db. When i try to run the following query, i get this error. 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 ='[email protected]'' at line 1

Does anyone know know why?

    @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);

Upvotes: 0

Views: 69

Answers (1)

Islingre
Islingre

Reputation: 2349

You are missing something between the two conditions offer.name = voucher.offer and email =:email, probably a WHERE, perhaps an AND/OR. I guess you wanted this:

@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);

Upvotes: 3

Related Questions