📄 confirm.java
字号:
package web;
/**
*普通用户登录验证程序
*/
import lms.*;
import java.sql.*;
import java.util.Vector;
import lms.User;
public class Confirm extends DataBase
{
private String UserID;
private String Password;
public Confirm()
{
super();
UserID = "";
Password = "";
}
public String getUserID()
{
return this.UserID;
}
public void setUserID(String UserID)
{
this.UserID = UserID;
}
public String getPassword()
{
return this.Password;
}
public void setPassword(String Password)
{
this.Password = Password;
}
/*
如果普通用户与管理员登录一起处理时,用这个方法分别得到两个sql语句;
public String getSql(){
}
*/
/*
check the UserID and Password when logon
*/
public boolean execute()
{
boolean success = false;
/*test*/
String sql="select * from User_table where UserID='"+UserID+"' and UserPassword='"+Password+"'";
try
{
rs = stm.executeQuery(sql);
if (rs.next())
{
UserID = rs.getString("UserID");
success = true;
}
rs.close();
this.close();
}
catch(Exception ex)
{
System.out.println(ex);
}
finally
{
return success;
}
}
/*
Get the User information
*/
public Vector information()
{
Vector v = new Vector();
// 用此方法时要保证execute()方法的返回值为true;
/*
String sql = "select * from User_table where UserID='"+UserID+"'";
写程序有好的习惯。。。。。命名一定要注意。。。。。
*/
//this.UserID = UserID;
/*
rs将为空。。。。。。。切记, Vector v 没有值,怪不得后面ElementAt(0)会抛出异常
在main.jsp里直接调用setUserID()方法、
*/
String sql = "select * from User_table where UserID='"+UserID+"'";
try
{
rs = stm.executeQuery(sql);
if(rs.next()){
User auser = new User();
auser.setUserID(rs.getString("UserID"));
//System.out.println("a");
auser.setCardID(rs.getString("cardID"));
//System.out.println("b");
auser.setIDNumber(rs.getString("IDNumber"));
//System.out.println("c");
auser.setUserName(rs.getString("UserName"));
//System.out.println("d");
auser.setSex(rs.getString("Sex"));
//System.out.println("e");
auser.setAddress(rs.getString("Address"));
//System.out.println("f");
auser.setPhone(rs.getString("Phone"));
//System.out.println("g");
auser.setEmail(rs.getString("Email"));
//System.out.println("h");
auser.setPenalty(rs.getFloat("Penalty"));
//System.out.println("i");
auser.setPriority(rs.getInt("Priority"));
v.addElement(auser);
}
}
catch(Exception ex)
{
System.out.println(ex);
System.out.println("Error: -- Read the table User_table......");
System.out.println("......error.....");
}
return v;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -