新手在写程序时,一定要胆大心细,而且要有耐心,不妥协,不懂就翻书,网上查资料,问朋友,坚决进行到底。
最近一直凭着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());
}
}
新闻热点
疑难解答