Java呼叫Oracle儲存過程的問題

rabbitbug發表於2005-05-13

儲存過程有一個陣列引數
Table of Varchar2(20)
在Java呼叫該儲存過程時
把用什麼資料型別傳進來呢?

我寫了下面的程式
String sql =
"{?=call PckgStudSltCourse.addStudPreSltCourse(?,?,?,?)}";
Connection con = null;
CallableStatement cs = null;
ResultSet rs = null;
int rets[] ;
int count = 0;
try
{
con = getConnection(dataSource);
cs = con.prepareCall(sql);
cs.registerOutParameter(1,java.sql.Types.INTEGER);
cs.setString(2,years);
cs.setString(3,termID);
cs.setString(4,studentID);
//cs.setObject(5,courseIDs,java.sql.Types.ARRAY); //用這句也丟擲ClassCastException
oracle.sql.ArrayDescriptor descriptor = oracle.sql.ArrayDescriptor.createDescriptor("TYPEVARCHARARRAY",(oracle.jdbc.OracleConnection)con); //就是這句丟擲了異常
oracle.sql.ARRAY array = new oracle.sql.ARRAY(descriptor,con,courseIDs);
((oracle.jdbc.OracleCallableStatement)cs).setArray(5,array);
cs.execute();
count = cs.getInt(1);
}
catch (Exception ex)
{
String errorMessage = "增加資料時出錯";
System.out.println(errorMessage);
ex.printStackTrace();
return -1;
}

下面是丟擲的異常


INFO [STDOUT] java.lang.ClassCastException
INFO [STDOUT] at com.saintbo.javabean.db.SltCourse.addStudPreCourseCourse(SltCourse.java:2105)
INFO [STDOUT] at com.saintbo.servlet.sltcourse.AddStudPreCourse.handle(AddStudPreCourse.java:75)
INFO [STDOUT] at com.saintbo.servlet.MyExtendedServlet.service(MyExtendedServlet.java:75)
INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:72)
INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
INFO [STDOUT] at org.jboss.web.tomcat.security.JBossSecurityMgrRealm.invoke(JBossSecurityMgrRealm.java:275)
INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
INFO [STDOUT] at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
INFO [STDOUT] at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
INFO [STDOUT] at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
INFO [STDOUT] at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
INFO [STDOUT] at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
INFO [STDOUT] at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
INFO [STDOUT] at java.lang.Thread.run(Thread.java:536)

相關文章