Java valueof (int) with integercache returns a value of 3 (1) for valueof
I face the problem of integercache:
Just call the database program
{ call UPDATE_PROC(?,?,?) } with params : [123,234,345,TEST1,567,TEST2]
The ibatis API sets the first parameter using:
typeHandler.setParameter(ps,i + 1,value,mapping.getJdbcTypeName());
Here PS is the reference to Preparedstatement, and I is the parameter index in the database process
It calls internally
ps.setInt(i,((Integer) parameter).intValue());
Call this call internally using the java reflection API:
public Object invoke(Object proxy,Method method,Object[] params) throws Throwable
When getting the integer value of I for a method call, the JVM calls the following method:
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. The value of cache [I (- integercache. Low)] is expressed as integercache Cache [129] ends. The integer cache index [129] should have a value of 1, but when I debug the code, I find the value 3 [129] at the index:
,-8,-7,-6,-5,-4,-3,-2,-1,3 **index[129]**,2,3 **index[131]**,4,5,6,7,8,9,10,11
Because integercache is the final type, there should be no duplicate values, such as 3 indexes [129] and [131]
So I finally have an exception:
java.sql.sqlException: Missing IN or OUT parameter at index:: 1
My question is how to do this? Please suggest
Solution
Some code may change the integer of the cache instance through reflection Value field