JSP, and then invoke the Oracle stored procedure in the bean.

Source: Internet
Author: User
Tags getmessage
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 ());
}
}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.