调用数据库程序就好
{ call UPDATE_PROC(?,?,?,?,?,?) } with params : [123, 234, 345, TEST1, 567, TEST2]
而iBatis API设置第一个参数使用:
typeHandler.setParameter(ps, i + 1, value, mapping.getJdbcTypeName());
i=0, value=123
这里ps是对PreparedStatement的引用,i是数据库过程中的参数索引.
它在内部打电话
ps.setInt(i, ((Integer) parameter).intValue());
i=1, parameter=123 (Note : i is int not Integer)
在内部使用Java反射api调用此调用:
public Object invoke(Object proxy, Method method, Object[] params) throws Throwable
method : setInt, params : [1, 123]
在获取方法调用的i的Integer值时,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]结束,整数缓存索引[129]应该有值1,但是当我调试代码时,我在索引处找到值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是最终类型,所以不应该有重复的值,例如3指数[129]和[131]
所以,我最终有例外:
java.sql.SQLException: Missing IN or OUT parameter at index:: 1
我的问题是如何做到这一点?
请建议my question is how this can be possible?
某些代码可能通过反射更改缓存实例的Integer.value字段.
精彩评论