基本用户身份验证

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值