java 存储过程 数组参数_执行数组参数的存储过程
今天在做移植java項目到云平臺的工作,遇到了執行數組參數的存儲過程的問題。先介紹一下怎么樣執行數組參數的存儲過程。
//創建descriptor,typeArrayName是數據庫中數組變量的名稱
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(typeArrayName, conn);
//將descriptor和valueObject mapping形成一個Array對象
ARRAY array = new ARRAY(descriptor, oracleConn, valueObject);
//callTest是CallableStatement對象,調用setObject方法設置參數
callTest.setObject(1, (Object) array);
callTest.execute();
問題的原因是ArrayDescriptor.createDescriptor方法中將conn會轉換成oracle.jdbc.OracleConnection對象.
但是Cloud平臺返回的conn是內部封裝好的GenPooledConnection對象。通過反編譯發現GenPooledConnection對象繼承了Connection對象。但是轉成oracle.jdbc.OracleConnection對象時就會拋出類型不匹配的錯誤。并且在new GenPooledConnection對象的時候,將Connection對象傳進來并保存到變量c中,因為c是私有成員變量。接下來通過反射拿到c。
public class GenPooledConnection
/* */ implements Connection, GenCacheable
/* */ {
private Connection c;
/* */ protected GenPooledConnection(String name, Connection c, Stack free, Hashtable active, long timeOut, boolean trace)
/* */ {
/* 36 */ this.id = new Integer(nextId++);
/* 37 */ this.name = name;
/* 38 */ this.c = c;
/* 39 */ this.free = free;
/* 40 */ this.active = active;
/* 41 */ this.timeOut = timeOut;
/* 42 */ this.trace = trace;
/* 43 */ this.starttime = System.currentTimeMillis();
/* 44 */ touch();
/* */ }
。。。
}
public Connection getOracleConnection(Connection conn) throws SWTException
{
Class> clazz;
Connection c = null;
try
{
clazz = Class.forName("com.ssc.faw.util.GenPooledConnection");
Field field = clazz.getDeclaredField("c");
field.setAccessible(true);
c = (Connection) field.get(conn);
}
catch (Exception ex)
{
Logger.error("Error Cause::" + ex.getMessage());
throw new SWTException(ex);
}
return c;
}
其實通過反射去拿私有函數也是沒辦法的事,誰讓不提供公有的方法去獲得connection對象呢,和TL討論后,他也沒辦法,而且他也早就這樣做過了,哈哈
分享到:
2011-08-29 17:37
瀏覽 1040
評論
總結
以上是生活随笔為你收集整理的java 存储过程 数组参数_执行数组参数的存储过程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java中的工厂模式_深入理解Java的
- 下一篇: 平均分组 java_java – 按属性