点击这里给我发消息 点击这里给我发消息

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

添加时间:2013-12-7
    相关阅读: JSP Oracle

  *执行一条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>
 
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册