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