java - 如何在单元测试中使用准备好的语句模拟 jdbctemplate
问题描述
嗨,我正在尝试在我的 mockito 单元测试用例中模拟以下代码,有人可以就如何模拟它提出可能的解决方案。谢谢
String prasobhName =
jdbcTemplate.query(
"select first_name from customer where last_name like ?",
new PreparedStatementSetter() {
public void setValues(PreparedStatement preparedStatement) throws
SQLException {
preparedStatement.setString(1, "nair%");
}
},
new ResultSetExtractor<Long>() {
public Long extractData(ResultSet resultSet) throws SQLException,
DataAccessException {
if (resultSet.next()) {
return resultSet.getLong(1);
}
return null;
}
}
);
解决方案
推荐阅读
- r - lm() 的响应优化
- python - 如何使用 Django Modelseirallizer 更新实例的粒子属性?
- java - 是否有引入 Java 数据类的预期日期?
- mysql - 如果另一个表B在mysql中有行,则选择表A中的所有行
- python - 在 Spyder 中使用 OpenPyxl 和 sqlite3 将数据从 Excel 文件导入数据库
- python - np.logical_or 与 reduce 返回不同的结果
- c - 如何从数组中删除 0 并将值分配给 C 中的锯齿状数组
- c# - 在 Where() 查询中将 Any() 的 lambda 表达式作为方法参数传递
- java - 为什么我的循环仅在我输入一个额外的换行符时才起作用,但在循环后跳过另一段代码?
- c++ - 用于自定义类的带有 {fmt} 的自定义格式说明符