国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

jsp中調用Bean,然后在Bean中調用oracle存儲過程

2024-08-29 13:32:20
字體:
來源:轉載
供稿:網友

  新手在寫程序時,一定要膽大心細,而且要有耐心,不妥協,不懂就翻書,網上查資料,問朋友,堅決進行到底。

  最近一直憑著asp的知識在摸索中前進,一跑坎坷,自不用說了。言歸正傳。

   建立一個登錄系統,要求達到以下目的。

   1、用戶通過bean來認證以及得到得到用戶信息。

   2、記錄用戶登錄信息,如用戶登錄次數,最后登錄時間。

   3、記錄操作日志。

  未解決及疑惑的問題:

  1、用戶登錄后的session是否可以通過bean來判斷。

  2、通過bean調用oracle存儲過程,返回select后的記錄集。

   操作步驟:

   1、建立用戶驗證bean:

 public boolean checkuser() throws exception {
  boolean flag=false;
  resultset rs=conn.executequery(getsql());
  if(rs.next()){
   userid    =rs.getstring("userid");
   username   =rs.getstring("username");
   userpwd    =rs.getstring("userpwd");
   userunit   =rs.getstring("userunit");
   userloadtime =rs.getdate("userloadtime");
   userloadnumeric=rs.getint("userloadnumber");
   flag=true;
  }
  rs.close();
  conn.closeconn();
  return flag;
 }

  通過返回的值判定用戶是否存在。

  2、記錄用戶登錄信息:

public void changelogininfo(string userid) throws exception{
  string sql="update systemusertable set userloadtime=sysdate,userloadnumber=userloadnumber+1 where userid='"+userid+"'";
  conn.executeupdate(sql);
 }

  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());
  }
 }
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 若尔盖县| 商城县| 文成县| 卓资县| 墨脱县| 宁武县| 高碑店市| 积石山| 乌苏市| 筠连县| 甘泉县| 福建省| 祁连县| 繁昌县| 沅陵县| 岑巩县| 原阳县| 遵义县| 隆德县| 连州市| 遂平县| 池州市| 分宜县| 广德县| 黄梅县| 信丰县| 松潘县| 滦南县| 当雄县| 宁远县| 城步| 会昌县| 大姚县| 浙江省| 湖北省| 四平市| 金塔县| 汝阳县| 大方县| 喜德县| 偏关县|