0

Mybatis throws an error which says there is problem with setting params. What could be wrong? I tested the SQL query and it's fine. I'm using graddle with spring.

Error querying database.
Cause: org.postgresql.util.PSQLException: ERROR: syntax error at or near "customer" Position: 245
The error may exist in services/CustomerService.java (best guess)
The error may involve services.CustomerService.findByPersonalCodeAndCountry-Inline
The error occurred while setting parameters

Code:

import com.luminor.dc.ccc.contracts.dao.Customer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@Mapper
public interface CustomerService {


    @Select("Select * FROM customer WHERE cust_personal_code= #{personalCode} AND cust_bank_country = #{country}")
    List<Customer> findByPersonalCodeAndCountry(@Param("personalCode") String personalCode,@Param("country") String country);
}

Controller

@RestController
@RequestMapping(value = "/v1/customers", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class CustomerController {

   private CustomerService customerService;

    public CustomerController(@Autowired CustomerService customerService) {
        this.customerService = customerService;
    }

    @GetMapping("/{personalCode}")
    public List<Customer> getCustomersByPersonalCode(@PathVariable String personalCode, @RequestHeader String country) {
        return customerService.findByPersonalCodeAndCountry(personalCode, country);
    }
}

Table

2
  • This error usually happens if the query is syntactically incorrect, e.g. select * customer where .... May it be that you had incorrect query, then fix it but still are running the old code? I would suggest to enable queries logging (in mybatis or in postgres) and check what query is really sent and executed in DB. Commented Oct 16, 2018 at 14:01
  • try using db level logging,useful link stackoverflow.com/questions/41001188/… Commented Oct 16, 2018 at 14:12

1 Answer 1

-1

Can you try below code ?

Controller method :
     @GetMapping("/{personalCode}")
        public List<Customer> getCustomersByPersonalCode(@PathVariable String personalCode, @RequestHeader(value="country") String country) {
            return customerService.findByPersonalCodeAndCountry(personalCode, country);
        }

@Results(value = { @Result(column = "id", property = "id"), 
        @Result(column = "cust_personal_code", property = "personalCode"), 
        @Result(column = "cust_bank_country ", property = "country")
    )}
    @Select("Select * FROM customer WHERE cust_personal_code= #{personalCode} AND cust_bank_country = #{country}")
    List<Customer> findByPersonalCodeAndCountry(@Param("personalCode") String personalCode, @Param("country") String country);

where id, personalCode,country : variables in customer POJO Table-> id(Integer),cust_personal_code (String ),cust_bank_country(String ) : columns in table

Sign up to request clarification or add additional context in comments.

6 Comments

sorry about that, that comma was just typo when I was pasting code In here
Did you tried giving result set and whole code change?
@jodymilers can you provide table details? and also make sure you are importing the package "org.apache.ibatis.annotations.Param"
added imports and table
@jodymilers table details ? type of columns ? i think the issue maybe with different datatypes in table and your parameter type
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.