Js|oracle| stored procedure Novice in the writing program, must be adventurousness, and must have patience, do not compromise, do not understand on the book, online search data, ask friends, resolutely carried out in the end.
Recently has been with the knowledge of the ASP in the groping forward, a run bumpy, since needless to say. Anyway
Establish a login system that requires the following purposes.
1, the user through the bean to authenticate and get the user information.
2, record user login information, such as user login times, the last logon time.
3, record the operation log.
Unresolved and puzzling questions:
1, the user login after the session can be judged by the bean.
2. Call the Oracle stored procedure through the bean and return the recordset after the select.
Operation Steps:
1. Establish 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;
}
Determines whether a user exists by the value returned.
2, record the user login 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 the operation log:
The first step is to establish 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 two, establish a method for manipulating stored procedures (overriding 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 three, 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 ());
}
}