gpt4 book ai didi

boolean - 返回一个 boolean 值 - jdbcTemplate

转载 作者:行者123 更新时间:2023-12-03 23:00:15 25 4
gpt4 key购买 nike

我想在此方法中使用返回一个 boolean 值:

public Boolean isSizeOk(String transactionId){ 
String sqlQuery = "SELECT true FROM customer_pool WHERE id = "+ transactionID + " AND level = 13)";

//The next line is the problem.
//If I am returning a Boolean List, I can write

List <Boolean> sizeResult = jdbcTemplate.queryForList(sqlQuery, Boolean.class, transactionId);

//But since I only want a boolean value, what will the statement be?
Boolean sizeResult = jdbcTemplate......?

return sizeResult;
}

请帮忙。谢谢。

最佳答案

如果要编写一个方法来检查数据库中是否存在记录,可以使用以下代码:

Integer cnt = jdbcTemplate.queryForObject(
"SELECT count(*) FROM customer_pool WHERE id = ? AND level = 13)", Integer.class, id);
return cnt != null && cnt > 0

关于boolean - 返回一个 boolean 值 - jdbcTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22860108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com