Call the bean in JSP and then call the Oracle stored procedure in bean

Source: Internet
Author: User

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());
  }
 }

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.