尝试连接select语句中的列时未找到列的异常

时间:2015-01-30 17:28:20

标签: java mysql

我的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.

1 个答案:

答案 0 :(得分:2)

||是MySQL中的OR运算符,它不会连接type'_'price的值。您可能希望/需要使用CONCAT函数:

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