WEB开发网
开发学院数据库Oracle Jsp中调用Oracle存储过程 阅读

Jsp中调用Oracle存储过程

 2008-09-04 12:50:04 来源:WEB开发网   
核心提示:*执行一条insert语句并传参数*/create or replace procedure p_test2(i in number) asbegininsert into t values (i,’x’||to_char(i));commit;end;/<%@ page language

*执行一条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>

Tags:Jsp 调用 Oracle

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接