Java Spring SimpleJDBCall返回错误的值
我使用SimpleJDBCall调用存储过程Java Spring SimpleJDBCall返回错误的值,java,spring,spring-jdbc,Java,Spring,Spring Jdbc,我使用SimpleJDBCall调用存储过程 public Map<String, Object> callStoredProcedure(SimpleJdbcCall jdbcCall, String procedureName, Map<String, Object> inParamMap) { log.info("Calling stored procedure with name : " + procedureName);
public Map<String, Object> callStoredProcedure(SimpleJdbcCall jdbcCall, String procedureName, Map<String, Object> inParamMap) {
log.info("Calling stored procedure with name : " + procedureName);
SqlParameterSource in = new MapSqlParameterSource(inParamMap);
Map<String, Object> out = jdbcCall.withProcedureName(procedureName).execute(in);
return out;
}
publicmap-callstoredprocesdure(SimpleJdbcCall-jdbcCall,String-procedureName,Map-inParamMap){
log.info(“调用名为“+procedureName”的存储过程);
SqlParameterSource in=新映射SqlParameterSource(inParamMap);
Map out=jdbcCall.withProcedureName(procedureName).execute(in);
返回;
}
其结果输出为
Key=#result-set-1,Value=[{=17.00}]
当我得到这样的类类型的值时,我很困惑
类class1=entry.getValue().getClass()
当我在数据库上执行时,我的sp返回17.00,但在jdbcCall代码中我得到了=17.00
任何评论都会有帮助。以下是我如何从以前的项目构建SimpleJDBCall的
createUpdateUsersSP = new SimpleJdbcCall(contactManagerJdbcT)
.withProcedureName(pb.getCreateUpdateUsersSp())
.declareParameters(
new SqlOutParameter("p_user_id", Types.NUMERIC),
new SqlOutParameter("p_update_stamp", Types.VARCHAR),
new SqlOutParameter("p_status", Types.VARCHAR),
new SqlOutParameter("p_failure_reason", Types.VARCHAR),
new SqlParameter("p_vonage_id", Types.VARCHAR),
new SqlParameter("p_mobile_did", Types.VARCHAR),
new SqlParameter("p_email_address", Types.VARCHAR),
new SqlParameter("p_name", Types.VARCHAR),
new SqlParameter("p_netname_id", Types.NUMERIC),
new SqlParameter("p_user_status", Types.VARCHAR),
new SqlParameter("p_image_update_stamp", Types.TIMESTAMP),
new SqlParameter("p_has_profile_image", Types.VARCHAR),
new SqlParameter("p_nick_name", Types.VARCHAR));
createUpdateUsersSP.setAccessCallParameterMetaData(false);
你有类似的东西可以展示给我们吗?显然,你的存储过程只会返回一个结果,但是
JdbcCall
的execute
方法试图返回输出参数的映射,按参数声明中的名称键入。由于没有参数声明,因此会得到一个ResultSet
,其中只有一行,没有列名,只有一个值17.00
我认为应该改为使用executeObject
,它将单个参数作为指定返回类型的对象返回
或
这是我提取价值的工作,因为我没有看到任何可行的答案
((Map)((List)out.get("#result-set-1")).get(0)).get("");
这给出了out参数内部的值。这是我的解决方法
Map<String,Object> simpleJdbcCallResult = simpleJdbcCall.execute(sqlParameterSource);
LinkedCaseInsensitiveMap<?> obj =
(LinkedCaseInsensitiveMap<?>)((List<?>)simpleJdbcCallResult.get("#result-set-1")).get(0);
Array[] values = (Array[]) obj.values().toArray()[0];
Map simpleJdbcCallResult=simpleJdbcCall.execute(sqlParameterSource);
LinkedCaseInsensitiveMap对象=
(LinkedCaseInsensitiveMap)((列表)SimpleJDBCAllResult.get(“#result-set-1”).get(0);
数组[]值=(数组[])对象值().toArray()[0];
不确定你在问什么。你能澄清一下吗?什么是列类型?或者更确切地说,存储过程返回的类型是什么?在构造SimpleJDBCall时是否声明了out参数?也许你可以发布它是如何构造的。不,我在构造时没有声明输出参数。你可能需要这样做。看看我的答案,首先我像这样构造SimpleJDBCall.SimpleJDBCall=newSimpleJDBCall(this.datasource);元数据处理基于JDBC驱动程序提供的数据库元数据。由于我们依赖于JDBC驱动程序,因此这种“自动检测“只能用于已知可提供准确元数据的数据库。目前包括Derby、MySQL、MicrosoftSQLServer、Oracle、DB2、Sybase和PostgreSQL。对于任何其他数据库,都需要显式声明所有参数。当然,即使数据库提供了必要的元数据,也可以显式声明所有参数。在这种情况下,您声明的参数将优先。”也许声明参数会有所帮助。您能试试吗?
((Map)((List)out.get("#result-set-1")).get(0)).get("");
Map<String,Object> simpleJdbcCallResult = simpleJdbcCall.execute(sqlParameterSource);
LinkedCaseInsensitiveMap<?> obj =
(LinkedCaseInsensitiveMap<?>)((List<?>)simpleJdbcCallResult.get("#result-set-1")).get(0);
Array[] values = (Array[]) obj.values().toArray()[0];