表单:
一:
二:
项目列表
1 package com.demo; 2 import util.util; 3 import java.sql.*; 4 import java.util.ArrayList; 5 import java.util.List; 6 import java.util.Scanner; 7 8 import Ke.Test; 9 public class LoginerDaolmpl { 10 static Connection conn; 11 static PreparedStatement ps = null; 12 static ResultSet rs; 13 static String sql = "select * from JiZ_user"; 14 static util ut= new util(); 15 static Scanner in = new Scanner(System.in); 16 public User addUser(User user) { 17 conn= ut.getConn(); 18 String sql="insert into JiZ_user values(?,?,?,?,?)"; 19 try { 20 ps=conn.prepareStatement(sql); 21 ps.setString(1,user.getName()); 22 ps.setString(2, user.getSex()); 23 ps.setString(3, user.getIdentity()); 24 ps.setString(4, user.getPhone()); 25 ps.setString(5, user.getPassword()); 26 27 int a=ps.executeUpdate(); 28 if(a>0) { 29 System.out.println("添加成功"); 30 31 } 32 else { 33 System.out.println("添加失败"); 34 } 35 }catch(Exception e) { 36 e.printStackTrace(); 37 } 38 try { 39 if(ps!=null)ps.close(); 40 if(conn!=null)conn.close(); 41 }catch(Exception e2) { 42 e2.printStackTrace(); 43 } 44 return user; 45 } 46 public static int uqdate(User user) { 47 int b=0; 48 conn=ut.getConn(); 49 ps=null; 50 sql="update JiZ_user set Sex=?,Phone=?,Password=? where Name=?"; 51 try { 52 ps=conn.prepareStatement(sql); 53 ps.setString(1,user.getSex()); 54 //ps.setString(2, user.getIdentity()); 55 ps.setString(2,user.getPhone()); 56 ps.setString(3,user.getPassword()); 57 ps.setString(4, user.getName()); 58 int a=ps.executeUpdate(); 59 if(a>0) { 60 b++; 61 System.out.println("修改成功"); 62 63 } 64 else { 65 System.out.println("修改失败"); 66 } 67 }catch(Exception e) { 68 e.printStackTrace(); 69 } 70 try { 71 if(ps!=null)ps.close(); 72 if(conn!=null)conn.close(); 73 }catch(Exception e2) { 74 e2.printStackTrace(); 75 } 76 return b; 77 78 } 79 public static int delete(String name) { 80 int b=0; 81 conn=ut.getConn(); 82 ps=null; 83 sql="delete from JiZ_user where Name=?"; 84 try { 85 ps=conn.prepareStatement(sql); 86 ps.setString(1, name); 87 int a=ps.executeUpdate(); 88 if(a>0) { 89 b++; 90 System.out.println("删除成功"); 91 92 } 93 else { 94 System.out.println("删除失败"); 95 } 96 }catch(Exception e) { 97 e.printStackTrace(); 98 } 99 try { 100 if(ps!=null)ps.close(); 101 if(conn!=null)conn.close(); 102 }catch(Exception e2) { 103 e2.printStackTrace(); 104 } 105 return b; 106 107 } 108 public User loadUser(String a) { 109 conn=ut.getConn(); 110 ps=null; 111 ResultSet rs=null; 112 User user=null; 113 sql="select * from JiZ_user where Name=?"; 114 try { 115 ps=conn.prepareStatement(sql); 116 ps.setString(1, a); 117 rs=ps.executeQuery(); 118 if(rs.next()) { 119 user=new User(); 120 user.setName(rs.getString("Name")); 121 user.setSex(rs.getString("Sex")); 122 user.setIdentity(rs.getString("Identity")) ; 123 user.setPhone(rs.getString("Phone")); 124 user.setPassword(rs.getString("Password")); 125 } 126 }catch(SQLException e) { 127 e.printStackTrace(); 128 }finally { 129 try { 130 if(ps!=null)ps.close(); 131 if(conn!=null)conn.close(); 132 }catch(Exception e2) { 133 e2.printStackTrace(); 134 } 135 } 136 return user; 137 } 138 public List<User> load(){ 139 conn=ut.getConn(); 140 ps=null; 141 ResultSet rs=null; 142 String id; 143 sql="select * from JiZ_user order by Name desc"; 144 List<User> users=new ArrayList<User>(); 145 User user=null; 146 try { 147 ps=conn.prepareStatement(sql); 148 rs=ps.executeQuery(); 149 while(rs.next()) { 150 user=new User(); 151 user.setName(rs.getString("Name")); 152 user.setSex(rs.getString("Sex")); 153 user.setIdentity(rs.getString("Identity")) ; 154 user.setPhone(rs.getString("Phone")); 155 user.setPassword(rs.getString("Password")); 156 users.add(user); 157 } 158 }catch(SQLException e) { 159 e.printStackTrace(); 160 }finally { 161 try { 162 if(ps!=null)ps.close(); 163 if(conn!=null)conn.close(); 164 }catch(Exception e2) { 165 e2.printStackTrace(); 166 } 167 } 168 return users; 169 } 170 }