从select参数化参数化值(BETWEEN的日期值,AND)
我的查询
SELECT COUNT(*) AS assignedtotalcount FROM ticket, ticket_data
WHERE ticket.`ticket_id` = ticket_data.`ticket_id`
AND ticket.`created` BETWEEN '?' AND '?'
从上面的查询参数化BETWEEN,AND
中的值Java代码
static String dateFrom = "2018-01-01";
static String dateTo = "2018-01-31";
String query = reportQuery.toString();
statement = connection.createStatement();
preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, dateFrom);
preparedStatement.setString(2, dateTo);
resultSet = preparedStatement.executeQuery(query);
执行时我得到以下异常
java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
请帮我解决
答案 0 :(得分:4)
不要引用占位符。您需要将parent-mvn-project
├── .mvn
│ ├── local-settings.xml
│ └── maven.config
├── submodule-A (if any submodules)
└── submodule-B (if any submodules)
更改为'?'
。
所以查询就像这样
?