我正在处理多次在PreparedStatement
中使用参数的情况:
SELECT * FROM SOME_TABLE
WHERE (A LIKE 'searchterm1' OR B LIKE 'searchterm1' OR C LIKE 'searchterm1')
AND (A LIKE 'searchterm2' OR B LIKE 'searchterm2' OR C LIKE 'searchterm2')
填充参数时,我必须多次提供每个参数(searchterm1和searchterm2):
try (PreparedStatement statement = connection.prepareStatement(
"SELECT * FROM SOME_TABLE " +
" WHERE (A LIKE ? OR B LIKE ? OR C LIKE ?) " +
" AND (A LIKE ? OR B LIKE ? OR C LIKE ?")) {
statement.setString(1, "searchterm1");
statement.setString(2, "searchterm1");
statement.setString(3, "searchterm1");
statement.setString(4, "searchterm2");
statement.setString(5, "searchterm2");
statement.setString(6, "searchterm2");
ResultSet resultSet = statement.executeQuery();
}
是否有办法在准备好的语句查询中多次引用同一参数,所以我只需要设置一次(每个参数)? 所以像
:searchterm1
或?1