Jsp中呼叫Oracle儲存過程

發表於2008-03-28
執行一條insert語句並傳引數*/
create or replace procedure p_test2(i in number) as
begin
insert into t values (i,'x'||to_char(i));
commit;
end;
/


<%@page import="java.sql.*"%>




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("

");
    }

    rs.close();
    stmt.close();
    conn.close();
%>

aaabbb
" + rs.getString(1) + "" + rs.getString(2) + "


out.print(conn.isClosed());
%>



相關文章