Source: Network/Editor: getting started with programming: Unknown
When writing a program, a newbie must be brave and patient. If he doesn't understand it, he must read the book, check the information on the Internet, ask his friends, and stick to it.
I have been working with ASP knowledge for a long time. Let's get down to the truth.
To create a logon system, follow these steps.
1. the user passes bean authentication and obtains the user information.
2. record user logon information, such as the number of user logins and the Last Logon Time.
3. Record operation logs.
Unsolved and doubtful issues:
1. Whether the session after user login can be determined by bean.
2. Call the Oracle stored procedure through bean and return the record set after select.
Procedure:
1. Create a user authentication 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;
}
The returned value is used to determine whether a user exists.
2. record user logon information:
public void changeLoginInfo(String userID) throws Exception{
String sql="update SystemUserTable set UserLoadTime=sysdate,UserLoadNumber=UserLoadNumber+1 where userID='"+userID+"'";
conn.executeUpdate(sql);
}
3. Record operation logs:
Step 1: Create a stored procedure
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;
Step 2: Create a method for operating the Stored Procedure (override the preparecall () method)
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;
}
Step 3: Execute the Stored Procedure
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());
}
}