package a1;
import java.sql.*;
public class Login
{   String logname,
           realname, 
           password,
           phone,
           address;
    String success="false",message=""; 
    Connection con;
    Statement sql; 
    ResultSet rs;
    public Login()
    {  //加载桥接器：
       try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          }
       catch(ClassNotFoundException e){}
    }
   //设置属性值、获取属性值的方法：
   public void setLogname(String name)
    {  logname=name;
    }
   public String getLogname()
    {return logname;
    }
   public void setPassword(String pw)
    {  password=pw;
    }
    public String getPassword()
    {return password;
    }
   public void setRealname(String name)
    {  realname=name;
    }
    public String getRealname()
    {return realname;
    }
   public void setPhone(String ph)
    {  phone=ph;
    }
   public String getPhone()
    {return phone;
    }
   public void setAddress(String ad)
    {  address=ad;
    }
   public String getAddress()
    {return address;
    }
   public String getSuccess()
    {return success;
    }
   //查询数据库的user表：
   public String getMessage()
    {try{
         con=DriverManager.getConnection("jdbc:odbc:shop","","");
         sql=con.createStatement();
          String condition=
         "SELECT * FROM user WHERE logname = "+"'"+logname+"'";
          rs=sql.executeQuery(condition);
          int rowcount=0;
          String ps=null;
         while(rs.next())
           { rowcount++;
             logname=rs.getString("logname");
             realname=rs.getString("realname");
             ps=rs.getString("password");
             phone=rs.getString("phone");
             address=rs.getString("address");
           } 
         if((rowcount==1)&&(password.equals(ps)))
           { message="ok";
             success="ok";
           }
        else
           {message="输入的用户名或密码不正确";
            success="false";
           }
        con.close();
        return message;
       }
     catch(SQLException e)
       { message="输入的用户名或密码不正确";
         success="false";
         return message;
       }
    }
}
