⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginbean.java

📁 JSP+SQL应用开发网上书店系统,采用BMP模式开发
💻 JAVA
字号:
package ejb;import ejb.*;import java.sql.*;import javax.sql.*;import javax.naming.*;import javax.ejb.*;import hell.*;import java.util.*;import java.math.*;import javax.naming.Context;import javax.naming.InitialContext;import javax.rmi.PortableRemoteObject;public class LoginBean implements SessionBean {  SessionContext sessionContext;  private userHome home2;  private Connection con;  private String dbName = "java:/MSSQL$XZW";  public void ejbCreate() throws CreateException {    try{        InitialContext initial = new InitialContext();        home2 = (userHome)initial.lookup("user");     }catch(Exception ne){     }  }  public void ejbRemove() {    /**@todo Complete this method*/  }  public void ejbActivate() {    /**@todo Complete this method*/  }  public void ejbPassivate() {    /**@todo Complete this method*/  }  public void setSessionContext(SessionContext sessionContext) {    this.sessionContext = sessionContext;    try {         makeConnection();      } catch (Exception ex) {          throw new EJBException("Unable to connect to database. " +             ex.getMessage());      }  }//  -------------------------------------------------private void makeConnection() throws NamingException, SQLException {      InitialContext ic = new InitialContext();      DataSource ds = (DataSource) ic.lookup(dbName);      con =  ds.getConnection();}  public userdetail checkpassword(String userId, String password) {    userdetail a = null; String selectStatement =     "select  userName from usertable where userId = ? and password = ?"; try{        PreparedStatement prepStmt =          con.prepareStatement(selectStatement);      prepStmt.setString(1, userId);      prepStmt.setString(2, password);      ResultSet rs = prepStmt.executeQuery();      if (rs.next()){        a = new userdetail(userId, rs.getString(1),password);      }      else      {         System.out.print("Login error");      } }catch(Exception ex){ } return a;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -