21,893
社区成员




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
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")//注释掉指定的类型就不会报错啦,保存成功
<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);
}
}
}
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();