標籤:oracle 數字溢出
org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{call updateUser(?, ?, ?, ?, ?, ?)}]; SQL state [99999]; error code [17026]; 數字溢出;
產生背景:
oracle資料庫從11g升級到12c調用預存程序的代碼是用的spring的StoredProcedure程式中有設定預存程序參數類型
new SqlOutParameter("userId",Types.
INTEGER)
create or replace procedure updateUser(userId in int ....) as...
在執行的時候,資料庫驅動將傳的參數類型和存數過程參數進行轉換,報這個錯。
原因:我用的舊版本spring的StoredProcedure可能是有個bug 他將你傳的參數類型給變了,最後不是integer轉int,是long轉int,這樣12c的驅動在轉的時候就會報錯。
解決方案:方法一、把
Types.
INTEGER換成Types.
NUMERIC 這樣可能12c上解決了,不知道兼不相容低版本了,沒試過。
方法二、換調存數過程的寫法
jt.execute(
new ConnectionCallback(){
public Object doInConnection(Connection connection)
throws SQLException, DataAccessException { CallableStatement st =
null; st=connection.prepareCall("{call updateUser(?,?,?,?,?)}"); st.registerOutParameter(1,Types.
INTEGER); st.registerOutParameter(4,Types.
INTEGER); st.registerOutParameter(5,Types.
VARCHAR); st.setInt(1,0); st.setInt(2,insID); st.setInt(3,1); st.setInt(4,1); st.setString(5,"OK"); st.execute(); CodeName c =
new CodeName(); c.setCode("" + st.getInt(4)); c.setName(st.getString(5));
return c; } });
oracle SQL state [99999]; error code [17026]; 數字溢出