You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSO2 DataService执行SUM聚合SQL查询时遇数据库错误

错误原因

这个异常的核心原因是:你在WSO2 DataService的配置中,将这条SELECT查询语句错误地配置为了更新类操作(比如用<update>标签定义查询)。WSO2 DS会根据配置的操作类型调用对应的JDBC方法:更新类操作会调用executeUpdate(),但SELECT语句只能用executeQuery()执行,因此触发了SQL异常。

解决办法
  1. 修正Data Service配置文件(.dbs)中的查询定义
    找到对应查询的配置块,将错误的<update>标签替换为<query>标签,示例如下:
    错误配置:

    <update id="getTotalNoteQuery">
        <sql>SELECT nom, SUM(note) as totalnote from etudiant where nom =?</sql>
        <param name="nom" sqlType="STRING"/>
    </update>
    

    正确配置:

    <query id="getTotalNoteQuery">
        <sql>SELECT nom, SUM(note) as totalnote from etudiant where nom =? GROUP BY nom;</sql>
        <param name="nom" sqlType="STRING"/>
        <result element="TotalNotes" rowName="Etudiant">
            <element column="nom" name="StudentName"/>
            <element column="totalnote" name="TotalScore"/>
        </result>
    </query>
    

    注:SQL语句中添加GROUP BY nom是为了符合SQL标准(非聚合列需出现在GROUP BY中),避免部分数据库抛出语法警告,这不是触发当前错误的原因,但能提升查询兼容性。

  2. 确认操作调用配置正确
    对应的operation需正确调用上述查询,示例配置:

    <operation name="getStudentTotalScore">
        <call-query href="getTotalNoteQuery">
            <with-param name="nom" query-param="nom"/>
        </call-query>
        <output type="json"/>
    </operation>
    
  3. 重新部署Data Service
    修改配置后,重新部署.dbs文件到WSO2 DS服务器,测试查询即可正常执行。

内容的提问来源于stack exchange,提问作者rania ben salem

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 02:50:56