java 存储过程 数组参数_执行数组参数的存储过程
今天在做移植java項(xiàng)目到云平臺(tái)的工作,遇到了執(zhí)行數(shù)組參數(shù)的存儲(chǔ)過(guò)程的問(wèn)題。先介紹一下怎么樣執(zhí)行數(shù)組參數(shù)的存儲(chǔ)過(guò)程。
//創(chuàng)建descriptor,typeArrayName是數(shù)據(jù)庫(kù)中數(shù)組變量的名稱
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor(typeArrayName, conn);
//將descriptor和valueObject mapping形成一個(gè)Array對(duì)象
ARRAY array = new ARRAY(descriptor, oracleConn, valueObject);
//callTest是CallableStatement對(duì)象,調(diào)用setObject方法設(shè)置參數(shù)
callTest.setObject(1, (Object) array);
callTest.execute();
問(wèn)題的原因是ArrayDescriptor.createDescriptor方法中將conn會(huì)轉(zhuǎn)換成oracle.jdbc.OracleConnection對(duì)象.
但是Cloud平臺(tái)返回的conn是內(nèi)部封裝好的GenPooledConnection對(duì)象。通過(guò)反編譯發(fā)現(xiàn)GenPooledConnection對(duì)象繼承了Connection對(duì)象。但是轉(zhuǎn)成oracle.jdbc.OracleConnection對(duì)象時(shí)就會(huì)拋出類型不匹配的錯(cuò)誤。并且在new GenPooledConnection對(duì)象的時(shí)候,將Connection對(duì)象傳進(jìn)來(lái)并保存到變量c中,因?yàn)閏是私有成員變量。接下來(lái)通過(guò)反射拿到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;
}
其實(shí)通過(guò)反射去拿私有函數(shù)也是沒(méi)辦法的事,誰(shuí)讓不提供公有的方法去獲得connection對(duì)象呢,和TL討論后,他也沒(méi)辦法,而且他也早就這樣做過(guò)了,哈哈
分享到:
2011-08-29 17:37
瀏覽 1040
評(píng)論
總結(jié)
以上是生活随笔為你收集整理的java 存储过程 数组参数_执行数组参数的存储过程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: java中的工厂模式_深入理解Java的
- 下一篇: 平均分组 java_java – 按属性