Java 在Spring JdbcTemplate中提取输出参数与结果集
我在研究SpringJdbc代码时注意到,当spring想要从输出参数中提取结果时,它直接使用类型不安全方法Java 在Spring JdbcTemplate中提取输出参数与结果集,java,spring,jdbc,jdbctemplate,Java,Spring,Jdbc,Jdbctemplate,我在研究SpringJdbc代码时注意到,当spring想要从输出参数中提取结果时,它直接使用类型不安全方法getObject(int index): 但是,为了从结果集中提取结果,他们需要尝试找出确切的类型: public static Object getResultSetValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException { if (requiredType == null
getObject(int index)
:
但是,为了从结果集中提取结果,他们需要尝试找出确切的类型:
public static Object getResultSetValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException {
if (requiredType == null) {
return getResultSetValue(rs, index);
}
Object value;
// Explicitly extract typed value, as far as possible.
if (String.class == requiredType) {
return rs.getString(index);
}
else if (boolean.class == requiredType || Boolean.class == requiredType) {
value = rs.getBoolean(index);
}
else if (byte.class == requiredType || Byte.class == requiredType) {
......
.....
public静态对象getResultSetValue(ResultSet rs,int index,Class requiredType)抛出SQLException{
if(requiredType==null){
返回getResultSetValue(rs,索引);
}
目标价值;
//尽可能显式地提取类型化值。
if(String.class==requiredType){
返回rs.getString(索引);
}
else if(boolean.class==requiredType | | boolean.class==requiredType){
值=rs.getBoolean(索引);
}
else if(byte.class==requiredType | | byte.class==requiredType){
......
.....
这背后的原因是什么?在搜索该主题后,我意识到 可能是因为缺少元数据对象,元数据对象提供了有关参数名称的信息 因为将要注册的输出参数名称传递到存储过程是可选的(您可以按索引注册输出参数),并且从callable语句返回的ParameterMetaData对象不会返回输出参数的名称
Spring;但是,填写参数名称(它要求用户在使用自己的API创建输出参数时进行设置)和参数值的映射。在该主题中搜索后,我意识到 可能是因为缺少元数据对象,元数据对象提供了有关参数名称的信息 因为将要注册的输出参数名称传递到存储过程是可选的(您可以按索引注册输出参数),并且从callable语句返回的ParameterMetaData对象不会返回输出参数的名称 Spring;但是,填充参数名称(它要求用户在使用自己的API创建输出参数时进行设置)和参数值的映射