DBMNG数据库管理与应用

书籍是全世界的营养品。生活里没有书籍,就好像没有阳光;智慧里没有书籍,就好像鸟儿没有翅膀。
当前位置:首页 > Oracle > 驱动连接

Jsp中调用Oracle存储过程的小例子

以下的例子转自csdn论坛:

*执行一条insert语句并传参数*/
create or replace procedure p_test2(i in number) as
begin
insert into t values (i,'x'||to_char(i));
commit;
end;
/

<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*"%>
<html>
<body>
<table>
<tr><td>aaa</td><td>bbb</td></tr>
<%
String driver = "oracle.jdbc.driver.OracleDriver";
String strUrl = "jdbc:oracle:thin:@192.168.1.6:1521:db";
   
   Class.forName(driver);
   Connection conn = DriverManager.getConnection(strUrl, "scott", "tiger");

   String procedure = "{call p_test2 (?) }";
   CallableStatement cstmt = conn.prepareCall(procedure);
   cstmt.setInt(1,33);
   cstmt.executeUpdate();

   Statement stmt = conn.createStatement();
   ResultSet rs = stmt.executeQuery("select * from t");

   while(rs.next())
   {
       out.println("<tr><td>" + rs.getString(1) + "</td><td>" + rs.getString(2) + "</td></tr>");
   }

   rs.close();
   stmt.close();
   conn.close();
%>
</table>
<p>
<%
out.print(conn.isClosed());
%>

</body>
</html>
</body> 
</html>
本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号