程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> jdbc-jsp調用存儲過程報錯,請幫忙看看。謝謝

jdbc-jsp調用存儲過程報錯,請幫忙看看。謝謝

編輯:編程綜合問答
jsp調用存儲過程報錯,請幫忙看看。謝謝

CREATE OR REPLACE procedure SAJET.test_levi(i in varchar)
as
begin
insert into temp_levi(name) values(i);
commit;
end;
/

<%String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@10.240.144.110:1521:SAJET";
Class.forName(driver);
Connection conn = DriverManager.getConnection(strUrl,"sajet","te");
out.print(conn);
String procedure = "{call sajet.test_levi(?)}";
CallableStatement cstmt = conn.prepareCall(procedure);
cstmt.setString(1,customer);
cstmt.execute();
conn.close();
out.print(cstmt);
out.print(customer);
%>

java.sql.SQLException: ORA-06550: line 1, column 8:
PLS-00103: Encountered the symbol "?" when expecting one of the following:

begin case declare exit for goto if loop mod null pragma
raise return select update while with
<外加雙引號的分界 ID> <連結變數> << close current
delete fetch lock insert open rollback savepoint set sql
execute commit forall merge pipe
The symbol "?" was ignored.

執行到cstmt.execute();就會報以上錯誤,請幫忙看看,非常感謝

最佳回答:


我自己找到問題了,雖然還是不怎麼明白。
在調用procedure的時候需要加上begin end;
改過後的代碼:
<%String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@10.240.144.110:1521:SAJET";
Class.forName(driver);
Connection conn = DriverManager.getConnection(strUrl,"sajet","tech");
out.print(conn);
//String procedure = "{call sajet.test_levi(?)}";
CallableStatement cstmt = conn.prepareCall("begin sajet.test_levi(?);end;");
cstmt.setString(1,"sssss");
cstmt.execute();
conn.close();
out.print(cstmt);
%>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved