我面临IntegerCache的问题:使用内部使用 iBatis PreparedStatement 类的 iBatis 数据访问框架。
调用数据库过程,如
{ call UPDATE_PROC(?,?,?,?,?,?) }
with params : [123, 234, 345, TEST1, 567, TEST2]
iBatis API 设置第一个参数时使用:
typeHandler.setParameter(ps, i + 1, value, mapping.getJdbcTypeName());
我=0,值=123
这里 ps 是对 PreparedStatement 的引用,i 是数据库过程中的参数索引。
它在内部调用
ps.setInt(i, ((Integer) parameter).intValue());
i=1,参数=123(注意:i 是 int 不是 Integer)
在内部使用 Java 反射 api 调用此调用:
public Object invoke(Object proxy, Method method, Object[] params) throws Throwable
方法:setInt,参数:[1, 123]
在为方法调用获取 i 的整数值时,JVM 调用下面的方法:
public static Integer valueOf(int i) {
assert IntegerCache.high >= 127;
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
IntegerCache.low = -128 IntegerCache.high = 127
的值IntegerCache.cache[i + (-IntegerCache.low)]
最终IntegerCache.cache[129]
应该1
在整数缓存索引 [129] 处有值,但是当我调试代码时,我3
在索引 [129] 处找到了值:
, -8, -7, -6, -5, -4, -3, -2, -1, 0, 3 **index[129]**, 2, 3 **index[131]**, 4, 5, 6, 7, 8, 9, 10, 11
由于 IntegerCache 是最终类型,因此不应在索引 [129] 和 [131] 处重复值,例如 3
所以,我最终例外:
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
我的问题是这怎么可能?请建议