📄 userlogin.java
字号:
/*
* Created on 2005-7-25
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package banksystem.business;
/**
* @author 曲本盛
*
* TODO Struts 项目实践
*/
import javax.sql.*;
import java.sql.*;
import banksystem.*;
import banksystem.PO.Customer;
import banksystem.exception.*;
public class UserLogin {
/**
* @param dataSource 数据源.
* @param customer 要保存的用户信息.
* @param gene 查询字符串生成器
*/
public void checkUser(DataSource dataSource,Customer customer,SearchGene gene)throws AccountNotExistException,UserPasswordInvalidException,SQLException{
Connection con = null;
PreparedStatement stat = null;
ResultSet result = null;
try{
String AccountID = customer.getAccountID();
String UserPass = customer.getLoginPass();
con = dataSource.getConnection();
stat = con.prepareStatement(Constants.SQL_CUSTOMER_SELECT+gene.getLoginWhereStr());
//System.out.println(Constants.SQL_CUSTOMER_SELECT+gene.getLoginWhereStr());
result = stat.executeQuery();
if(!result.next()){
throw new AccountNotExistException(Constants.ERRORS_ACCOUNT_NOT_EXIST);
}
//组装以参数传入的Customer对象的实例,必须按顺序读出否则报无效索引异常
customer.setAccountID(result.getString(1));
customer.setUserName(result.getString(2));
customer.setSex(result.getString(3));
customer.setLoginPass(result.getString(4));
customer.setTradePass(result.getString(5));
customer.setID(result.getString(6));
customer.setPhone(result.getString(7));
customer.setAddr(result.getString(8));
customer.setOpenDate(result.getString(9));
customer.setBalance(Double.valueOf(result.getDouble(10)));
customer.setStatus(result.getString(11));
if(!UserPass.equals(customer.getLoginPass())){
throw new UserPasswordInvalidException(Constants.ERRORS_USER_PASSWARD_INVALID);
}
}
catch(AccountNotExistException ae){
ae.fillInStackTrace();
throw ae;
}
catch(UserPasswordInvalidException ue){
ue.fillInStackTrace();
throw ue;
}
catch(SQLException e){
e.fillInStackTrace();
throw e;
}
finally{
try{
if(con!=null){
con.close();
}
if(stat!=null){
stat.close();
}
}
catch(SQLException e){
e.fillInStackTrace();
throw e;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -