我目前正在使用下面这样的语法工作良好
Object[] oParams = new Object[] {
Integer.valueOf(this.userId),
Date.valueOf(this.startDate),
Date.valueOf(this.endDate)
};
jdbcTemplate.queryForList(sql, oParams);
如果在
PHP
我们可以简单地添加索引,但在java中,以下语法会引发错误
oParams[3] = Integer.valueOf(this.userId)
如果我添加如下值,
List<Object> oParams = new ArrayList<Object>();
oParams.add(Integer.valueOf(this.userId));
oParams.add(Date.valueOf(this.startDate));
oParams.add(Date.valueOf(this.endDate));
jdbcTemplate.queryForList(sql, oParams);
它会导致以下错误,
org.postgresql.util.PSQLException: Can't infer the SQL type to use for an instance of java.util.ArrayList. Use setObject() with an explicit Types value to specify the type to use.
at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:949)
提前谢谢。