📄 buyerbean.java
字号:
/*
* @(#)BuyerBean.java 1.0 06/03/03
*
* Copyright 2006 林刘炜
*/
package beans;
import java.sql.*;
/**
* 该Bean利用 DBOperation Bean连接数据库
* 对会员ID和密码进行合法性验证
*
* @version 1.0
* @author 林刘炜
*/
public class BuyerBean
{
/**
* 一个String类型的变量引用,存放会员的ID编号
*/
private String id= null;
/**
* 同上,存放会员的密码
*/
private String pwd= null;
/**
* 同上,存放会员的真实姓名
*/
private String name= null;
/**
* 一个int类型的变量引用,存放会员的登录次数
*/
private int logonTimes= -1;
/**
* 构造一个新的<b>BuyerBean</b>
*/
public BuyerBean(){
}
/**
* 该方法连接数据库,查询会员的ID号和密码是否正确
* 正确的话,就获取会员的登录次数和真实姓名
* 最后更新会员的登录次数
*
* @return int 顾客历史以来的登录次数
*/
public int getLogonTimes(){
DBOperation database = new DBOperation();
try{
ResultSet rst = database.executeSQL("select * from buyerInfo where id ='"+id+"' and pwd ='"+pwd+"'");
if( rst.next() ){
logonTimes = rst.getInt("logonTimes");
name = rst.getString("name");
}
if( logonTimes != -1 ){
database.executeSQL("update buyerInfo set logonTimes = logonTimes +1 where id = '"+id+"'");
}
}catch(SQLException e){
e.printStackTrace();
}finally{
try{
database.closeDatabase();
}catch(SQLException e){
e.printStackTrace();
}
}
return logonTimes;
}
/**
* 设置会员的ID编号
*
* @param id String类型
*/
public void setID(String id){
this.id = id;
}
/**
* 设置会员的密码
*
* @param pwd String类型
*/
public void setPwd(String pwd){
this.pwd = pwd;
}
/**
* 获得会员的真实姓名
*
* @return String类型
*/
public String getName(){
return name;
}
/**
* main方法把该Bean作为一个application来测试,真正发布时可以删除
*/
public static void main(String[] args){
BuyerBean buyer = new BuyerBean();
buyer.setID("111");
buyer.setPwd("111");
System.out.println(buyer.getLogonTimes());
System.out.println(buyer.getName());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -