gpt4 book ai didi

java - 尝试在 select 语句中连接列时出现未找到列异常

转载 作者:行者123 更新时间:2023-11-29 07:44:27 25 4
gpt4 key购买 nike

我的java代码中有:

StringBuilder stringQuery = new StringBuilder("select product_id, type || '_' || price as info ");
SQLQuery q = createSQLQuery(stringQuery.toString());
q.list();

我收到此错误:

Caused by: java.sql.SQLException: Column '' not found.

最佳答案

||是 MySQL 中的 OR 运算符,它不会连接 type'_'price 的值。也许您想要/需要使用 CONCAT功能:

StringBuilder stringQuery = new StringBuilder("select product_id, CONCAT(type, '_', price) as info ");
//...

关于java - 尝试在 select 语句中连接列时出现未找到列异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28241396/

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