login.java
上传用户:sxlinghang
上传日期:2022-07-20
资源大小:1405k
文件大小:2k
源码类别:

数据库编程

开发平台:

Java

  1. package bookshop.run;
  2. /**
  3.  * <p>管理用户登录的类 </p>
  4.  */
  5. import bookshop.util.*;
  6. public class login extends DataBase {
  7.         private String username; //登录用户名
  8.         private String passwd; //登录密码
  9.         private boolean isadmin; //是否管理员登录
  10.         private long userid=0; //用户ID号
  11.         public login() throws Exception{
  12.                 super();
  13.                 username = "";
  14.                 passwd = "";
  15.                 isadmin = false;
  16.         }
  17.         public String getUsername() {
  18.                 return username;
  19.         }
  20.         public void setUsername(String newusername) {
  21.                 username = newusername;
  22.         }
  23.         public String getPasswd() {
  24.                 return passwd;
  25.         }
  26.         public void setPasswd(String newpasswd) {
  27.                 passwd = newpasswd;
  28.         }
  29.         public boolean getIsadmin() {
  30.                 return isadmin;
  31.         }
  32.         public void setIsadmin(boolean newIsadmin) {
  33.                 isadmin = newIsadmin;
  34.         }
  35.         public long getUserid() {
  36.                 return userid;
  37.         }
  38.         public void setUserid (long uid) {
  39.                 userid = uid;
  40.         }
  41.         /**
  42.          * 获得查询用户信息的sql语句
  43.          * @return
  44.          */
  45.         public String getSql() {
  46.                 if (isadmin) {
  47.                         sqlStr = "select * from BookAdmin where adminuser = '" +
  48.                             dataFormat.toSql(username) + "' and adminpass = '" +
  49.                             dataFormat.toSql(passwd) + "'";
  50.                 }else {
  51.                         sqlStr = "select * from shop_user where username = '" +
  52.                             username + "' and password = '" + passwd + "'";
  53.                 }
  54.                 return sqlStr;
  55.         }
  56.         /**
  57.          * 执行查询
  58.          * @return
  59.          * @throws java.lang.Exception
  60.          */
  61.         public boolean excute() throws Exception {
  62.                 boolean flag = false;
  63.                 DataBase db = new DataBase();
  64.                 db.connect();
  65.                 stmt = db.conn.createStatement ();
  66.                 rs = stmt.executeQuery(getSql());
  67.                 if (rs.next()){
  68.                         if (!isadmin)
  69.                         {
  70.                                 userid = rs.getLong("id");
  71.                         }
  72.                         flag = true;
  73.                 }
  74.                 rs.close();
  75.                 return flag;
  76.         }
  77. };