1. 程式人生 > >java呼叫儲存過程無法取得返回引數

java呼叫儲存過程無法取得返回引數

環境:資料庫sql server2005,jdk1.6 ,myeclipse,驅動jdts1.2.2

執行以下程式碼,報錯:

報錯資訊為:

java.sql.SQLException: Output parameters have not yet been processed. Call getMoreResults().
    at net.sourceforge.jtds.jdbc.ParamInfo.getOutValue(ParamInfo.java:159)
    at net.sourceforge.jtds.jdbc.JtdsCallableStatement.getOutputValue(JtdsCallableStatement.java:116)
    at net.sourceforge.jtds.jdbc.JtdsCallableStatement.getString(JtdsCallableStatement.java:310)

報錯資訊說得很明白,就是輸出結果引數未處理,必須呼叫getMoreResults()方法以判斷是否還有結果集。

然後修改程式碼,問題解決:

其中改為以下程式碼也不報錯: