package daoimpl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import dao.bankDao;
import entity.Bank;
import entity.User;
import util.DBUtil;
public class bankdaoimpl implements bankDao {
public void save(Bank bank) {
Connection conn = null;
PreparedStatement pst = null;
try {
conn = DBUtil.getConnection();
String sql = "insert into bank(name,sex,birthday,phone,num,balance,passwd,bankid) values (?,?,?,?,?,?,?,?)";
pst = conn.prepareStatement(sql);
pst.setString(1, bank.getName());
pst.setString(2, bank.getSexString());
pst.setDate(3, new java.sql.Date(bank.getBirthday().getTime()));
pst.setString(4, bank.getPhone());
pst.setString(5, bank.getNum());
pst.setInt(6, bank.getBalance());
pst.setString(7, bank.getPasswd());
pst.setString(8, bank.getBankid());
pst.execute();
} catch (Exception e) {
e.printStackTrace();
}finally {
if(pst!=null) {try{pst.close();}catch(Exception e2) {}}
if(conn!=null) {try{conn.close();}catch(Exception e2) {}}
}
}
public void update(String bankid,String num,int balance) {
Connection conn = null;
PreparedStatement pst = null;
try {
conn = DBUtil.getConnection();
String sql = "update bank set balance = balance + ? where bankid = ? and num=?";
pst = conn.prepareStatement(sql);
pst.setInt(1, balance);
pst.setString(2, bankid);
pst.setString(3, num);
pst.execute();
} catch (Exception e) {
e.printStackTrace();
}finally {
if(pst!=null) {try{pst.close();}catch(Exception e2) {}}
if(conn!=null) {try{conn.close();}catch(Exception e2) {}}
}
}
@Override
public void delete(String bankid,String num,int balance) {
Connection conn = null;
PreparedStatement pst = null;
try {
conn = DBUtil.getConnection();
String sql = "update bank set balance = balance - ? where bankid = ? and passwd =?";
pst = conn.prepareStatement(sql);
pst.setInt(1, balance);
pst.setString(2, bankid);
pst.setString(3, num);
pst.execute();
} catch (Exception e) {
e.printStackTrace();
}finally {
if(pst!=null) {try{pst.close();}catch(Exception e2) {}}
if(conn!=null) {try{conn.close();}catch(Exception e2) {}}
}
}
@Override
public Bank findBynum(int num) {
return null;
}
public void transfer(String bankid,String passwd,String bankid2,int balance) {
Connection conn = null;
PreparedStatement pst = null;
Connection conn1 = null;
PreparedStatement pst1 = null;
try {
conn = DBUtil.getConnection();
conn1 = DBUtil.getConnection();
String sql = "update bank set balance = balance - ? where bankid = ? and passwd = ?;";
pst = conn.prepareStatement(sql);
pst.setInt(1, balance);
pst.setString(2, bankid);
pst.setString(3, passwd);
pst.execute();
String sql2 = "update bank set balance = balance + ? where bankid = ?;";
pst1 = conn1.prepareStatement(sql2);
pst1.setInt(1, balance);
pst1.setString(2, bankid2);
pst1.execute();
} catch (Exception e) {
e.printStackTrace();
}finally {
if(pst!=null) {try{pst.close();}catch(Exception e2) {}}
if(conn!=null) {try{conn.close();}catch(Exception e2) {}}
}
}
public List<Bank> findBynum(String num,String passwd,String bankid){
String Bankid = null;
String Num = null;
Connection conn = null;
ResultSet rs = null;
Statement st = null;
try {
conn = DBUtil.getConnection();
String sql = "select * from bank where num = "+num+" and passwd = "+passwd+" and bankid = "+bankid;
st = conn.prepareStatement(sql);
rs = st.executeQuery(sql);
List<Bank> list = new ArrayList<Bank>();
while(rs.next()) {
Bank bank = new Bank();
bank.setName(rs.getString("name"));
bank.setSexString(rs.getString("sex"));
bank.setBirthday(rs.getDate("birthday"));
bank.setPhone(rs.getString("phone"));
num = rs.getString("num");
Num = num.substring(0,3)+"***"+ num.substring(14);
bank.setNum(Num);
bank.setBalance(rs.getInt("balance"));
bank.setPasswd(rs.getString("passwd"));
bankid = rs.getString("bankid");
Bankid = bankid.substring(0, 3) + "****" + bankid.substring(12);
bank.setBankid(Bankid);
list.add(bank);
}
return list;
} catch (Exception e) {
e.printStackTrace();
} finally {
if(rs!=null) {try{rs.close();}catch(Exception e2) {}}
if(conn!=null) {try{rs.close();}catch(Exception e2) {}}
}
return null;
}
public void regist(String username,String passwd,String phone) {
Connection conn = null;
PreparedStatement pst = null;
try {
conn = DBUtil.getConnection();
String sql = "insert into user(username,passwd,phone) values (?,?,?)";
pst = conn.prepareStatement(sql);
pst.setString(1, username);
pst.setString(2, passwd);
pst.setString(3, phone);
pst.execute();
} catch (Exception e) {
e.printStackTrace();
}finally {
if(pst!=null) {try{pst.close();}catch(Exception e2) {}}
if(conn!=null) {try{conn.close();}catch(Exception e2) {}}
}
}
public User login(String username,String passwd) {
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
try {
conn = DBUtil.getConnection();
String sql = "select * from user where username = ?";
pst = conn.prepareStatement(sql);
pst.setString(1, username);
rs = pst.executeQuery();
while(rs.next()) {
User user = new User();
user.setUsername(rs.getString("username"));
user.setPasswd(rs.getString("passwd"));
return user;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(rs!=null) {try{rs.close();}catch(Exception e2) {}}
if(conn!=null) {try{rs.close();}catch(Exception e2) {}}
}
return null;
}
@Override
public User toLogin(String username) {
Connection conn = null;
ResultSet rs = null;
PreparedStatement pst = null;
try {
conn = DBUtil.getConnection();
String sql = "select * from user where username = ?";
pst = conn.prepareStatement(sql);
pst.setString(1, username);
rs = pst.executeQuery();
while(rs.next()) {
User user = new User();
user.setUsername(rs.getString("username"));
return user;
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if(rs!=null) {try{rs.close();}catch(Exception e2) {}}
if(conn!=null) {try{rs.close();}catch(Exception e2) {}}
}
return null;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
大学生期末答辩项目,基于servlet+HTML+css+JavaScript+jsp+MySQL实现的银行管理系统,包含sql
共43个文件
html:9个
class:7个
java:7个
需积分: 0 1 下载量 102 浏览量
2024-03-07
08:53:36
上传
评论
收藏 1.17MB ZIP 举报
温馨提示
大学生期末答辩项目,银行管理系统,后端java前端JavaScript与HTML跟css,数据库MySQL
资源推荐
资源详情
资源评论
收起资源包目录
银行管理系统.zip (43个子文件)
bank.sql 2KB
bank
.classpath 837B
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.jdt.core.prefs 364B
.jsdtscope 567B
org.eclipse.wst.common.component 464B
org.eclipse.wst.common.project.facet.core.xml 345B
org.eclipse.wst.jsdt.ui.superType.container 49B
src
Verify
CreateVerifyCodeServlet.java 2KB
db.properties 190B
controller
MainServlet.java 6KB
dao
bankDao.java 623B
daoimpl
bankdaoimpl.java 7KB
entity
User.java 489B
Bank.java 2KB
util
DBUtil.java 2KB
build
classes
Verify
CreateVerifyCodeServlet.class 3KB
db.properties 190B
controller
MainServlet.class 6KB
dao
bankDao.class 723B
daoimpl
bankdaoimpl.class 9KB
entity
User.class 850B
Bank.class 2KB
util
DBUtil.class 3KB
WebContent
draw.html 2KB
regist.html 2KB
list.jsp 2KB
account.html 3KB
WEB-INF
lib
mysql-connector-java-5.1.26.jar 836KB
commons-dbcp2-2.7.0.jar 204KB
commons-pool2-2.8.0.jar 127KB
commons-logging-1.2.jar 60KB
web.xml 820B
main.html 2KB
error.jsp 780B
save.html 2KB
login.html 2KB
Transfer.html 2KB
check.html 2KB
error.html 425B
META-INF
MANIFEST.MF 39B
.project 904B
.gitignore 8B
共 43 条
- 1
资源评论
小小唐同学
- 粉丝: 26
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功