WEB开发网
开发学院数据库Oracle jsp中调用Bean然后在Bean中调用oracle存储过程 阅读

jsp中调用Bean然后在Bean中调用oracle存储过程

 2008-05-13 16:08:31 来源:WEB开发网   
核心提示:3、记录操作日志:第一步,建立存储过程create or replace procedure proc_writeNote(description in varchar2,wName in varchar2,wIP in varchar2)isbegininsert into Systemnote (Id,Descri

3、记录操作日志:

第一步,建立存储过程

create or replace procedure proc_writeNote(
 description in varchar2,
 wName in varchar2,
 wIP in varchar2
 )
is
begin
 insert into Systemnote (Id,Description,Wname,Wip) values(Autoaddid.Nextval,description,wName,wIP);
 commit;
end proc_writeNote;

第二步、建立操作存储过程的方法(重写prepareCall()方法)

 public CallableStatement prepareCall(String produce){
  try {
   conn = DriverManager.getConnection(DBUrl, UserID, UserPWD);
   cstmt=conn.prepareCall(produce);
  }
  catch (SQLException ex) {
   System.err.print("prepareCall():"+ex.getMessage());
  }
  return cstmt;
 }

第三步,执行存储过程

 public void writeNote(String description,String wName,String wIP){
  String sql="{call proc_writeNote(?,?,?)}";
  try {
   CallableStatement cstmt=conn.prepareCall(sql);
   cstmt.setString(1, description);
   cstmt.setString(2,wName);
   cstmt.setString(3,wIP);
   cstmt.executeUpdate();
  }
  catch (SQLException ex) {
   System.out.print("writeNote():"+ex.getMessage());
  }
 }

上一页  1 2 

Tags:jsp 调用 Bean

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