程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> Jsp中調用Oracle存儲過程的小例子

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

編輯:關於JSP

    /*執行一條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>

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved