java - 为什么我的 jdbcTemplate 查询没有返回任何行?
问题描述
我有一个用 spring-boot 构建的 API。请求将 JSON 发送到构建请求对象的端点。请求对象将其 Product 对象列表发送到一个方法,以更新 Product 中的 productDimensions 对象。
为了获得尺寸,我将 Sku 字符串和 Size 字符串发送到使用 jdbcTemplate 设置的名为 ProductRepository 的类(我认为)
该方法没有失败,但 SqlRowSet 返回 0 行,我无法弄清楚。请注意,Java 不是我的主要语言,所以我有点困惑。
我试过https://spring.io/guides/gs/relational-data-access/和其他几个 SO 链接
public class ProductRepository {
@Autowired
JdbcTemplate jdbcTemplate;
public SqlRowSet findBySkuSize(String sku, String size) {
return jdbcTemplate.queryForRowSet("SELECT * from PRODUCT_DIMENSIONS where SKU = '" + sku + "' and SIZE = '" + size + "'");
}
}
这就是我正在做的调用 ProductRepository
private ProductRepository productRepository;
//constructor
public FreightCalculationService(ProductRepository productRepository)
{
this.productRepository = productRepository;
}
private Obj Method(params){
Obj obj = new Obj()
SqlRowSet dataRows = productRepository.findBySkuSize(params);
我希望我的 H2 数据库中的数据在我的 SqlResultSet 中显示为一行,但是当我检查时,总行数为 0..
编辑:我的 jdbcTemplate 已填充,我已经清理了一些代码。
编辑:当我在调试器中查看 SqlRowSet 对象时,我看到它不工作 [![在此处输入图像描述][2]][2] 调试控制台中没有引发错误。
[![[2]:https://i.stack.imgur.com/sSen0.png][2]][2]
所以看起来 Sql 语句有问题,当我将查询更改为 SELECT * FROM PRODUCT_DIMENSIONS 时,我得到 4 行,但是当我尝试易受 sql 注入影响的方法时,我什么也没得到,这可能是因为Java连接字符串的方式?我要查看准备好的陈述以查看是否有解决方法的任何人。
解决方案
推荐阅读
- android - 构建 gradle 时出错 - com.google.android.gms:play-services-basement 正在被其他各种库请求
- python - 双重装饰器,为什么我的封闭函数之一没有执行?
- react-native - 无法在反应式中解析模块加密
- javascript - Ionic3 标签(如点击功能)在 InnerHTML 中不起作用
- jquery - JSP Error Unable to locate tag attribute info for tag attribute aria- describeby spring form
- asp.net-mvc - 在控制器 [ASP.Net MVC] 中动态检查验证
- php - 使用php替换多种格式的电话前缀
- php - 如何从 Laravel 5.5 中的 DB Json 值比较和获取数据
- javascript - 将图像上传到firebase没有错误,但图像没有出现在存储中
- c++ - 移动后是否需要重置 std::list ?