Chinaunix首页 | 论坛 | 博客
  • 博客访问: 103543587
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: Oracle

2008-04-30 23:44:09

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"%>
< 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();
%>

aaa bbb
" + rs.getString(1) + "" + rs.getString(2) + "


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


阅读(1573) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~