您的位置:首页 > 数据库

基本用户身份验证

2005-08-04 11:59 316 查看
package lib;
public class Constants
{    
    //用于检测用户合法性的表(即用户帐户信息表)
    public static final String userInfoTableName = "userInfo";
    public static final String userNameFiledName = "userName";
    public static final String passwordFiledName = "password";
   
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package model;
import java.sql.*;
import lib.DBConnector;
import lib.Constants;
public class CheckLogin
{
 void check(String userName, String password)
 {
  String sql;
  DBConnector dbc = new DBConnector();
  dbc.getConnection();
  sql = "select * from " + Constants.userInfoTableName + " where ";
  sql += Constants.userNameFiledName + "=" + "'" + userName + "'" + " and ";
  sql += Constants.passwordFiledName + "=" + "'" + password + "'";
  ResultSet rs = dbc.executeQuery(sql);
  try
  {
   System.out.println(sql);
  if(!rs.next())
   System.out.println("用户名或密码错误!");
  else
   System.out.println("OK");
  }catch(Exception e){System.out.println("用户名或密码错误!");} 
 }
 public static void main(String[] args)
 {
  CheckLogin cl = new CheckLogin();
  cl.check("yin","123456");
 }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐