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);
%>