From 55fb341b78a7ef4d371409225a54b6a30ee22c1d Mon Sep 17 00:00:00 2001 From: nxist2202005093 <3231319577@qq.com> Date: Wed, 26 Jun 2024 09:59:18 +0800 Subject: [PATCH] ADD file via upload --- Accountcxsimple.java | 130 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 Accountcxsimple.java diff --git a/Accountcxsimple.java b/Accountcxsimple.java new file mode 100644 index 0000000..f8a9492 --- /dev/null +++ b/Accountcxsimple.java @@ -0,0 +1,130 @@ +package JavaDaoimple; + + +import JavaBean.Accountcxs; +import JavaDao.AccountDaocxs; +import wuziqiyem.JDBCUtil; + +import java.sql.*; +import java.util.ArrayList; + +public class Accountcxsimple implements AccountDaocxs { + public ArrayList findAll() { + try{ + Connection connection= JDBCUtil.getConnection(); + String sql = "select * from account"; + Statement sts = connection.createStatement(); + ResultSet rs = sts.executeQuery(sql); + while (rs.next()) { + Accountcxs ac = new Accountcxs(); + ac.setCountrycxs(rs.getString("country")); + ac.setEmallcxs(rs.getString("email")); + ac.setNamecxs(rs.getString("Name")); + ac.setPasswordcxs(rs.getString("password")); + ac.setPhonecxs(rs.getString("phone")); + ac.setUseridcxs(rs.getString("userid")); + } + rs.close(); + sts.close(); + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + + } + @Override + public Accountcxs findByID (String userid) { + Accountcxs ac = new Accountcxs(); + try { + Connection connection= JDBCUtil.getConnection(); + String sql="select * from account where userid=?"; + PreparedStatement pstm=connection.prepareStatement(sql); + pstm.setString(1,userid); + ResultSet rs=pstm.executeQuery(); + + if(rs.next()){ + ac.setCountrycxs(rs.getString("country")); + ac.setEmallcxs(rs.getString("email")); + ac.setNamecxs(rs.getString("Name")); + ac.setPasswordcxs(rs.getString("password")); + ac.setPhonecxs(rs.getString("phone")); + ac.setUseridcxs(rs.getString("userid")); + System.out.println(ac.getUseridcxs()+" "+ac.getCountrycxs()+" "+ac.getEmallcxs()+" "+ac.getNamecxs()+" "+ac.getPasswordcxs()+" "+ac.getPhonecxs()); + }else{ + System.out.println("当前用户不存在"); + rs.close(); + pstm.close(); + connection.close(); + + + } + } catch (Exception e) { + e.printStackTrace(); + } + + + return ac; + } + + @Override + public int mod(Accountcxs accountcxs) { + try { + Connection connection= JDBCUtil.getConnection(); + String sql="update account set addr = ? , city=?,country=?,email=?,name=?,password=?,phone=?where userid=?"; + PreparedStatement pstm=connection.prepareStatement(sql); +// ResultSet rs=pstm.executeQuery(); +// while(rs.next()){ + pstm.setString(3,accountcxs.getCountrycxs()); + pstm.setString(4,accountcxs.getEmallcxs()); + pstm.setString(5,accountcxs.getNamecxs()); + pstm.setString(6,accountcxs.getPasswordcxs()); + pstm.setString(7,accountcxs.getPhonecxs()); + pstm.setString(8,accountcxs.getUseridcxs()); + pstm.executeUpdate(); +// } +// System.out.println(accountcxs.getUseridcxs()+" "+accountcxs.getAddrcxs()+" "+accountcxs.getCitycxs()+" "+accountcxs.getCountrycxs()+" "+accountcxs.getEmallcxs()+" "+accountcxs.getNamecxs()+" "+accountcxs.getPasswordcxs()+" "+accountcxs.getPhonecxs()); + } catch (Exception e) { + e.printStackTrace(); + } + return 0; + } + + @Override + public int delect(String userid) { + try { + Connection connection= JDBCUtil.getConnection(); + String sql="delete from account where userid=?"; + PreparedStatement pstm=connection.prepareStatement(sql); + pstm.setString(1,userid); + pstm.executeUpdate(); + } catch (Exception e) { + e.printStackTrace(); + } + return 0; + } + + @Override + public int insert(Accountcxs accountcxs) { + int num=0; + try { + Connection connection= JDBCUtil.getConnection(); + String sql="insert into account values(?,?,?,?,?,?)"; + PreparedStatement pstm=connection.prepareStatement(sql); + pstm.setString(1, accountcxs.getUseridcxs()); + pstm.setString(2, accountcxs.getPasswordcxs()); + pstm.setString(3, accountcxs.getEmallcxs()); + pstm.setString(4, accountcxs.getNamecxs()); + pstm.setString(5, accountcxs.getCountrycxs()); + pstm.setString(6, accountcxs.getPhonecxs()); + pstm.executeUpdate(); + } catch (Exception e) { + e.printStackTrace(); + } + return num; + } + + + + +} \ No newline at end of file