在jdbcTemplate.queryForObject中将字符串作为参数传递

时间:2018-09-12 09:24:37

标签: java spring-jdbc jdbctemplate

我正在尝试在jdbcTemplate.queryForObject函数中将字符串作为第三个参数传递,但是出现错误“方法queryForObject不适用于该参数”。下面是我的代码。

String twoYearBeforeDate = adhpDetailUtil.getDateBeforeTwoYear();
        final String QUERY = "select * " +  "from gfc.LSI_ELGBLTY " + "where INSURANCE_ID = ? and " + "SYS_CD = ? and " + "LSI_CNCLN_DT >= ?";
        Object[] params = new Object[]  {
                request.getInsuranceId(),request.getSystemId()};
            String ids = jdbcTemplate.queryForObject(QUERY, params, twoYearBeforeDate, new AdhpDetailsRequestMapper());

我该如何传递字符串'twoYearBeforeDate',并将对象作为第三个参数进行查询。如果我将'twoYearBeforeDate'的类型更改为int,它将起作用,但是我需要将其作为字符串变量传递。谁能对此有个想法。预先感谢。

1 个答案:

答案 0 :(得分:0)

尝试一下:

Object[] params = new Object[]  {
            request.getInsuranceId(),
            request.getSystemId(), 
            twoYearBeforeDate};
String ids = jdbcTemplate.queryForObject(QUERY, params, new AdhpDetailsRequestMapper());