工具类:
package com.yang.Dao;
import java.sql.ResultSet;
import java.sql.SQLException;
public class AdministerDao extends BaseDao{
/**
* 01-管理员登录
* @param id 管理员账号
* @param custPwd 管理员密码
* @return 是否登录成功
*/
public boolean login(String name,String Pwd) {
try {
String sql = "select * from administrator where adminName=? and adminPwd=?";
Object[] params = {name,Pwd};
ResultSet rs = this.myexecuteQuery(sql, params);
if(rs.next()) {
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
/**
* 02-增加用户
*/
public int addCustomer(Object[] params) {
String sql = "insert into customer values (?,?,?,?,?,now())";
return this.myexecuteUpdate(sql, params);
}
/**
* 03-查询存储总额
*/
public double sumMoney() {
String sql = "select sum(custMoney) from customer";
try {
ResultSet rs = this.myexecuteQuery(sql,null);
if(rs.next()) {
return rs.getDouble(1);
}
} catch (SQLException e) {
e.printStackTrace();
}
return 0;
}
/**
* 04-查询有钱人
*/
public void richMan() {
String sql = "select * from customer order by custMoney desc limit 0,10";
ResultSet rs = this.myexecuteQuery(sql, null);
System.out.println("------------------------------------");
System.out.println("卡号\t姓名\t拥有财富");
try {
while(rs.next()) {
String custNumber = rs.getString("custNumber");
String custName = rs.getString("custName");
String custMoney = rs.getString("custMoney");
System.out.println(custNumber+"\t"+custName+"\t"+custMoney);
}
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
package com.yang.Dao;
import java.sql.ResultSet;
import java.sql.SQLException;
public class CustomerDao extends BaseDao{
/**
* 01-储户登录
* @param id 储户账号
* @param custPwd 储户密码
* @return 是否登录成功
*/
public boolean login(String id,String custPwd) {
try {
String sql = "select * from customer where custNumber=? and custPwd=?";
Object[] params = {id,custPwd};
ResultSet rs = this.myexecuteQuery(sql, params);
if(rs.next()) {
return true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return false;
}
/**
* 02-存款
*/
public int addMoney(String custNum,Double Money) {
String sql = "update customer set custMoney=custMoney+? where custNumber=?";
Object[] params = {Money,custNum};
int count = this.myexecuteUpdate(sql, params);
return count;
}
/**
* 03-查询储户余额
*/
public double queryMoney(String custNum) {
try {
String sql = "select custMoney from customer where custNumber