求助,jdbctemplate调用sqlServer存储过程传入表参数,不支持从 UNKNOWN 到 OTHER 的转换,要怎么正确传入表参数

qq_21322817 2024-08-16 10:59:19

List<TableBoxVO> tableBoxVOS = new ArrayList<>();
        List<TableWipItemTypeVO> tableWipItemTypeVOS = new ArrayList<>();
        TableBoxVO tableBoxVO;
        TableWipItemTypeVO tableWipItemTypeVO;
        Map<String, Object> tableData;
        Map<String, Object> tableBoxData;
        List<Map<String, Object>> tableValues = new ArrayList<>();
        List<Map<String, Object>> tableBoxValues = new ArrayList<>();
        for(BoxInfo boxInfo: processTransferVO.getTableBoxVOS()){
            tableBoxData = new HashMap<>();
            tableBoxData.put("FlowBox",boxInfo.getBoxCode());
            tableBoxData.put("qty",boxInfo.getQty());
            tableBoxVO = new TableBoxVO(boxInfo);
            tableBoxVOS.add(tableBoxVO);
            tableBoxValues.add(tableBoxData);
        }
        for(MaterialVO materialVO: processTransferVO.getTableWipItemTypeVOS()){
            tableData = new HashMap<>();
            tableData.put("itemID",122);
            tableData.put("itemCode",null);
            tableData.put("itemName",null);
            tableData.put("supplierCode",null);
            tableData.put("lot",null);
            tableData.put("boxCode",null);
            tableData.put("qty", null);
            tableWipItemTypeVO = new TableWipItemTypeVO(materialVO);
            tableWipItemTypeVOS.add(tableWipItemTypeVO);
            tableValues.add(tableData);
        }
        SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
                .withProcedureName("saveWipProductData_Batch_p")
                .declareParameters(
                        new SqlParameter("WipNo", Types.VARCHAR),//工单号
                        new SqlParameter("WipQty", Types.INTEGER),//工单数量
                        new SqlParameter("ItemID", Types.INTEGER),//产品Id
                        new SqlParameter("RouteEntry_ID", Types.INTEGER),//工艺路线表体ID
                        new SqlParameter("MachineID", Types.VARCHAR),//机台号
                        new SqlParameter("UserID", Types.VARCHAR),//用户ID
                        new SqlParameter("UserName", Types.VARCHAR),//用户名称
                        new SqlParameter("GoodProductsQty", Types.DECIMAL),//良品数
                        new SqlParameter("RejectsQty", Types.DECIMAL),//不良数
                        new SqlParameter("remark", Types.VARCHAR),//备注
                        new SqlParameter("CurrentBox", Types.VARCHAR),//当前框
                        new SqlParameter("FlowBox", Types.VARCHAR),//转移框
                        new SqlParameter("dt", Types.OTHER, "Wip_Item_type")//领料信息
//                        new SqlParameter("dt_FlowBox_Qty", Types.OTHER, "FlowBox_Qty_type")//转移框类别
                );
        Map<String, Object> inParams = new HashMap<>();
        inParams.put("WipNo", processTransferVO.getOrderNo());
        inParams.put("WipQty", processTransferVO.getOrderQty());
        inParams.put("ItemID", processTransferVO.getMaterialId());
        inParams.put("RouteEntry_ID", processTransferVO.getProcessVO().getSysId());
        inParams.put("MachineID", processTransferVO.getMachineId());
        inParams.put("UserID", processTransferVO.getUserId());
        inParams.put("UserName", processTransferVO.getUserName());
        inParams.put("GoodProductsQty", processTransferVO.getGoodQty());
        inParams.put("RejectsQty", 0);
        inParams.put("remark", processTransferVO.getRemark());
        inParams.put("CurrentBox", processTransferVO.getCurrentBox());
        inParams.put("FlowBox", processTransferVO.getFlowBox());
        inParams.put("dt", tableValues);
//        inParams.put("dt_FlowBox_Qty", new MapSqlParameterSource(tableBoxData));
        String returnMsg = jdbcCall.execute(inParams).get("Fmsg").toString();
        if(returnMsg.indexOf("保存成功") !=-1){
            return new ResultVO(ResultVO.Result.SUCCESS);
        }
        return new ResultVO(ResultVO.Result.FAIL, returnMsg);
    }

 

 

 


Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{call saveWipProductData_Batch_p(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}]; SQL state [null]; error code [0]; 不支持从 UNKNOWN 到 OTHER 的转换。; nested exception is com.microsoft.sqlserver.jdbc.SQLServerException: 不支持从 UNKNOWN 到 OTHER 的转换。] with root cause

...全文
546 8 打赏 收藏 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_21322817 2024-08-19
  • 打赏
  • 举报
回复
  new SqlParameter("WipNo", Types.VARCHAR),
                    new SqlParameter("WipQty", Types.INTEGER),
                    new SqlParameter("ItemID", Types.INTEGER),
                    new SqlParameter("RouteEntry_ID", Types.INTEGER),
                    new SqlParameter("MachineID", Types.VARCHAR),
                    new SqlParameter("UserID", Types.VARCHAR),
                    new SqlParameter("UserName", Types.VARCHAR),
                    new SqlParameter("GoodProductsQty", Types.DECIMAL),
                    new SqlParameter("RejectsQty", Types.DECIMAL),
                    new SqlParameter("remark", Types.VARCHAR),
                    new SqlParameter("CurrentBox", Types.VARCHAR),
                    new SqlParameter("FlowBox", Types.VARCHAR),
                    //new SqlParameter("dt", Types.STRUCT, "Wip_Item_type")//注释掉指定的类型就不会报错啦,保存成功




愿时光不负. 2024-08-16
  • 打赏
  • 举报
回复

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>9.4.1.jre8</version>
</dependency>

import com.microsoft.sqlserver.jdbc.SQLServerDataTable;
import com.microsoft.sqlserver.jdbc.SQLServerException;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;

import java.sql.Types;
import java.util.HashMap;
import java.util.Map;

public class YourClass {
    public void yourMethod() throws SQLServerException {
        // 创建 SQLServerDataTable
        SQLServerDataTable table = new SQLServerDataTable();
        table.addColumnMetadata("itemID", Types.INTEGER);
        table.addColumnMetadata("itemCode", Types.VARCHAR);
        table.addColumnMetadata("itemName", Types.VARCHAR);
        table.addColumnMetadata("supplierCode", Types.VARCHAR);
        table.addColumnMetadata("lot", Types.VARCHAR);
        table.addColumnMetadata("boxCode", Types.VARCHAR);
        table.addColumnMetadata("qty", Types.DECIMAL);

        // 添加数据
        for (Map<String, Object> data : tableValues) {
            table.addRow(data.get("itemID"), data.get("itemCode"), data.get("itemName"), 
                         data.get("supplierCode"), data.get("lot"), data.get("boxCode"), data.get("qty"));
        }

        // 调用存储过程
        SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
                .withProcedureName("saveWipProductData_Batch_p")
                .declareParameters(
                        new SqlParameter("WipNo", Types.VARCHAR),
                        new SqlParameter("WipQty", Types.INTEGER),
                        new SqlParameter("ItemID", Types.INTEGER),
                        new SqlParameter("RouteEntry_ID", Types.INTEGER),
                        new SqlParameter("MachineID", Types.VARCHAR),
                        new SqlParameter("UserID", Types.VARCHAR),
                        new SqlParameter("UserName", Types.VARCHAR),
                        new SqlParameter("GoodProductsQty", Types.DECIMAL),
                        new SqlParameter("RejectsQty", Types.DECIMAL),
                        new SqlParameter("remark", Types.VARCHAR),
                        new SqlParameter("CurrentBox", Types.VARCHAR),
                        new SqlParameter("FlowBox", Types.VARCHAR),
                        new SqlParameter("dt", Types.STRUCT, "Wip_Item_type")
                );

        Map<String, Object> inParams = new HashMap<>();
        inParams.put("WipNo", processTransferVO.getOrderNo());
        inParams.put("WipQty", processTransferVO.getOrderQty());
        inParams.put("ItemID", processTransferVO.getMaterialId());
        inParams.put("RouteEntry_ID", processTransferVO.getProcessVO().getSysId());
        inParams.put("MachineID", processTransferVO.getMachineId());
        inParams.put("UserID", processTransferVO.getUserId());
        inParams.put("UserName", processTransferVO.getUserName());
        inParams.put("GoodProductsQty", processTransferVO.getGoodQty());
        inParams.put("RejectsQty", 0);
        inParams.put("remark", processTransferVO.getRemark());
        inParams.put("CurrentBox", processTransferVO.getCurrentBox());
        inParams.put("FlowBox", processTransferVO.getFlowBox());
        inParams.put("dt", table); // 使用 SQLServerDataTable 作为参数传递

        String returnMsg = jdbcCall.execute(inParams).get("Fmsg").toString();
        if (returnMsg.contains("保存成功")) {
            System.out.println("Success");
        } else {
            System.out.println("Fail: " + returnMsg);
        }
    }
}

qq_21322817 2024-08-16
  • 举报
回复
@愿时光不负. 不支持从 TVP 到 STRUCT 的转换。
qq_21322817 2024-08-16
  • 举报
回复
@qq_21322817 public ResultVO submitOrder(ProcessTransferVO processTransferVO) throws SQLServerException { SQLServerDataTable dtWipItem = new SQLServerDataTable(); dtWipItem.addColumnMetadata("ItemID", Types.INTEGER); dtWipItem.addColumnMetadata("ItemCode", Types.VARCHAR); dtWipItem.addColumnMetadata("ItemName", Types.VARCHAR); dtWipItem.addColumnMetadata("SupplierCode", Types.VARCHAR); dtWipItem.addColumnMetadata("Lot", Types.VARCHAR); dtWipItem.addColumnMetadata("BoxCode", Types.VARCHAR); dtWipItem.addColumnMetadata("Qty", Types.DECIMAL); for (MaterialVO materialVO : processTransferVO.getTableWipItemTypeVOS()) { dtWipItem.addRow(materialVO.getMaterialId(), materialVO.getMaterialCode(), materialVO.getMaterialName(), materialVO.getSupplierCode(), materialVO.getBatchNo(), materialVO.getBoxCode(), materialVO.getQty()); } SQLServerDataTable dtFlowBoxQty = new SQLServerDataTable(); dtFlowBoxQty.addColumnMetadata("FlowBox", Types.VARCHAR); dtFlowBoxQty.addColumnMetadata("Qty", Types.DECIMAL); for (BoxInfo boxInfo : processTransferVO.getTableBoxVOS()) { dtFlowBoxQty.addRow(boxInfo.getBoxCode(), boxInfo.getQty()); } SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate) .withProcedureName("saveWipProductData_Batch_p") .declareParameters( new SqlParameter("WipNo", Types.VARCHAR), new SqlParameter("WipQty", Types.INTEGER), new SqlParameter("ItemID", Types.INTEGER), new SqlParameter("RouteEntry_ID", Types.INTEGER), new SqlParameter("MachineID", Types.VARCHAR), new SqlParameter("UserID", Types.VARCHAR), new SqlParameter("UserName", Types.VARCHAR), new SqlParameter("GoodProductsQty", Types.DECIMAL), new SqlParameter("RejectsQty", Types.DECIMAL), new SqlParameter("remark", Types.VARCHAR), new SqlParameter("CurrentBox", Types.VARCHAR), new SqlParameter("FlowBox", Types.VARCHAR), new SqlParameter("dt", Types.STRUCT, "dbo.Wip_Item_type"), new SqlParameter("dt_FlowBox_Qty", Types.STRUCT, "dbo.FlowBox_Qty_type") ); Map&lt;String, Object&gt; inParams = new HashMap&lt;&gt;(); inParams.put("WipNo", processTransferVO.getOrderNo()); inParams.put("WipQty", processTransferVO.getOrderQty()); inParams.put("ItemID", processTransferVO.getMaterialId()); inParams.put("RouteEntry_ID", processTransferVO.getProcessVO().getSysId()); inParams.put("MachineID", processTransferVO.getMachineId()); inParams.put("UserID", processTransferVO.getUserId()); inParams.put("UserName", processTransferVO.getUserName()); inParams.put("GoodProductsQty", processTransferVO.getGoodQty()); inParams.put("RejectsQty", 0); inParams.put("remark", processTransferVO.getRemark()); inParams.put("CurrentBox", processTransferVO.getCurrentBox()); inParams.put("FlowBox", processTransferVO.getFlowBox()); inParams.put("dt", dtWipItem); inParams.put("dt_FlowBox_Qty", dtFlowBoxQty); String returnMsg = jdbcCall.execute(inParams).get("Fmsg").toString(); if(returnMsg.contains("保存成功")){ return new ResultVO(ResultVO.Result.SUCCESS); } return new ResultVO(ResultVO.Result.FAIL, returnMsg); }
qq_21322817 2024-08-16
  • 举报
回复
@qq_21322817 还是不行🙂‍↔️
1条回复
愿时光不负. 2024-08-16
  • 打赏
  • 举报
回复

SqlParameterSource[] paramSourceArray = tableValues.stream()
    .map(MapSqlParameterSource::new)
    .toArray(SqlParameterSource[]::new);

Map<String, Object> inParams = new HashMap<>();
inParams.put("WipNo", processTransferVO.getOrderNo());
inParams.put("WipQty", processTransferVO.getOrderQty());
inParams.put("ItemID", processTransferVO.getMaterialId());
inParams.put("RouteEntry_ID", processTransferVO.getProcessVO().getSysId());
inParams.put("MachineID", processTransferVO.getMachineId());
inParams.put("UserID", processTransferVO.getUserId());
inParams.put("UserName", processTransferVO.getUserName());
inParams.put("GoodProductsQty", processTransferVO.getGoodQty());
inParams.put("RejectsQty", 0);
inParams.put("remark", processTransferVO.getRemark());
inParams.put("CurrentBox", processTransferVO.getCurrentBox());
inParams.put("FlowBox", processTransferVO.getFlowBox());
inParams.put("dt", paramSourceArray);

String returnMsg = jdbcCall.execute(inParams).get("Fmsg").toString();

qq_21322817 2024-08-16
  • 举报
回复
@愿时光不负. 还是提示‘不支持从 UNKNOWN 到 ARRAY 的转换’,如果类型换成new SqlParameter("dt", Types.VARCHAR, "Wip_Item_type"),就会提示 操作数类型冲突: nvarchar 与 Wip_Item_type 不兼容
大气污染是影响公众健康与生态环境的重要问题,精准的空气质量时空预测与污染源贡献度量化是精准治污的关键支撑。针对现有研究多源融合不充分、时空关联刻画不足、预测与源解析割裂三方面缺陷,本文设计实现了城市空气质量时空预测与污染源贡献度分析系统,融合监测、气象、工业排放与交通四类数据,构建基于时空注意力的LSTM(STAM-LSTM)预测模型与基于正定矩阵因子分解(PMF)的源解析模型,形成数据融合-特征工程-预测-源解析-可视化闭环。 系统实现四类数据时空对齐与融合,构建时序与空间邻域特征,以普通克里金插值生成1km网格浓度场;STAM-LSTM引入时空注意力自适应学习站点间污染传输时变权重,以72小时输入预测未来24小时逐小时PM2.5浓度;PMF识别交通、工业、燃煤、扬尘与二次生成五个源因子,量化各源全年贡献度并分析时空演变。 实验明:STAM-LSTM预测RMSE 24.6、MAE 17.8、R² 0.88,相对LSTM基线(30.2)提升18.5%;普通克里金插值误差8.9,优于反距离加权(11.4);源解析显示交通源28.4%、工业源23.1%、燃煤源19.6%为主要贡献源,冬季燃煤源升至27.3%、早高峰交通源达34.8%,下风向工业源贡献高出上风向8~12个百分点;减排情景显示交通源减排20%可使年均PM2.5下降5.7%,与源贡献度排序一致。 系统按五模块14组件实现,功能测试16项用例全部通过,为大气污染预警、源管控与减排政策制定提供了决策依据。 【课程报告内容】 摘要 第1章 绪论 第2章 相关技术与理论 第3章 系统需求分析 第4章 系统总体设计 第5章 系统详细设计与实现 第6章 系统测试与分析 第7章 总结与展望 参考文献 附件-实现指南
基于iTransformer-BiGRU-KAN多模型融合的滚动轴承剩余寿命预测研究(Python代码实现)内容概要:本文提出了一种基于iTransformer-BiGRU-KAN多模型融合的滚动轴承剩余寿命预测方法,旨在通过结合多种先进深度学习模型的优势,提升在复杂工况下的预测精度与鲁棒性。该方法利用iTransformer捕捉长期时间序列中的全局依赖关系,通过BiGRU模型提取双向时序特征,最后引入KAN(Kernel Attention Network)增强非线性映射与关键特征的自适应加权能力,实现对轴承退化过程的精准建模。文中详细介绍了模型架构设计、训练流程及在公开数据集上的实验验证,结果明该融合模型相比单一模型在预测精度和稳定性方面均有显著提升。; 适合人群:具备一定机器学习与深度学习基础,从事设备故障诊断、工业大数据分析或智能运维相关领域的研究人员及工程技术人员,尤其适合研究生及以上学历或有相关项目经验的专业人员。; 使用场景及目标:①应用于工业设备状态监测与预测性维护系统中,实现对滚动轴承等关键部件剩余寿命的精准预测;②为复杂时间序列回归任务提供多模型融合的设计思路与技术参考;③推动深度学习在智能制造与工业物联网领域的落地应用。; 阅读建议:建议读者结合Python代码实现部分,深入理解各子模型的接口设计与融合逻辑,重点关注特征融合机制与注意力权重的可视化分析,以便在实际项目中灵活调整与优化模型结构。

21,889

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧