熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

Jsp中調用Oracle存儲過程的小例子

2013-11-15 11:58:54  來源: JSP教程 

  /*執行一條insert語句並傳參數*/
create or replace procedure p_test(i in number) as
begin
insert into t values (i’x||to_char(i));
commit;
end;


<%@ page language=”java” contentType=”text/html;charset=gb″%>
<%@page import=”javasql*”%>
<html>
<body>
<table>
<tr><td>aaa</td><td>bbb</td></tr>
<%
String driver = “oraclejdbcdriverOracleDriver”;
String strUrl = “jdbc:oracle:thin:@::db”;

  ClassforName(driver);
Connection conn = DriverManagergetConnection(strUrl “scott” “tiger”);

  String procedure = “{call p_test (?) }”;
CallableStatement cstmt = connprepareCall(procedure);
cstmtsetInt();
cstmtexecuteUpdate();

  Statement stmt = conncreateStatement();
ResultSet rs = stmtexecuteQuery(”select * from t”);

  while(rsnext())
{
outprintln(”<tr><td>” + rsgetString() + “</td><td>” + rsgetString() + “</td></tr>”);
}

  rsclose();
stmtclose();
connclose();
%>
</table>
<p>
<%
outprint(connisClosed());
%>

  </body>
</html>
</body>
</html>


From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20020.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.