JAVA SUM SQL语句怎么拼 带动态传参的 一直报错

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA SUM SQL语句怎么拼 带动态传参的 一直报错相关的知识,希望对你有一定的参考价值。

public String WaresCollect(String str)
Connection connection = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
String number = null;
try
//获得链接对象
connection = CiteUtil.getConnection();
//针对商品信息表聚合查询拼写SQL语句
String sql = "select SUM ? from SPMXTable";
//将SQL语句发送数据库获得语句对象
preparedStatement = connection.prepareStatement(sql);
//通过语句对象实现动态传参数
preparedStatement.setString(1,"("+str+")");
//返回结果集
resultSet = preparedStatement.executeQuery();
//拿到总和结果值
while(resultSet.next())
number = resultSet.getString(1);

catch (ClassNotFoundException e)
e.printStackTrace();
catch (SQLException e)
e.printStackTrace();
finally
CiteUtil.closeAllSource(connection, preparedStatement, resultSet);

return number;

这是我代码说什么字符串不能用聚合函数 在数据库里面不是可以带列名么!求助!

参考技术A select sum(字段) from biao

以上是关于JAVA SUM SQL语句怎么拼 带动态传参的 一直报错的主要内容,如果未能解决你的问题,请参考以下文章

python----积累---使用传参的方式构造sql语句

Mybatis中#{}和${}传参的区别

mybatis中#{}和${}传参的区别

Mybatis中#{}和${}传参的区别及#和$的区别小结

Mybatis中#{}和${}传参的区别及#和$的区别小结(转)

idea把本地的改成传参的