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

2008-02-23 07:58:45来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

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

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:创建访问DB2 Everyplace的JSP应用程序

下一篇:JSP连接数据库方法大全