新手在寫程序時,一定要膽大心細,而且要有耐心,不妥協,不懂就翻書,網上查資料,問朋友,堅決進行到底。
最近一直憑著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());
}
}
新聞熱點
疑難解答