用java做的管理系统_对于使用javaweb技术制作简单管理系统的学习

1 packagedao;2 importbean.Account;3 importbean.User;4 importutil.DButil;5 import java.sql.*;6

7 importjava.sql.Connection;8 importjava.sql.PreparedStatement;9 importjava.sql.ResultSet;10 importjava.sql.SQLException;11 importjava.sql.Statement;12 importjava.util.ArrayList;13 importjava.util.List;14

15

16 importbean.Account;17 importutil.DButil;18

19 public classUserDao {20 DButil DB =newDButil();21 private static UserDao userDao =newUserDao();22

23 public staticUserDao getUserDao()24 {25 returnuserDao;26

27 }28 /*public boolean checkUser(String username ,String password) {29 DButil DB = new DButil();30 String sql="select username,password from account where username=? and password=?";31 //String sql = "select username,password,jurisdiction from account where username='"+username+"' and password='"+password+"'";32 Connection conn = null;33 PreparedStatement ps = null;34 boolean flag = false;35 try {36 conn = DB.getConn();37 ps = conn.prepareStatement(sql);38 ps.setString(1, username);39 ps.setString(2, password);40 //ps.setInt(3, jurisdiction);41 ResultSet rs = ps.executeQuery();42 if(rs.next())43 {44

45 flag=true;46 }47

48 } catch (Exception e) {49

50 flag=false;51 e.printStackTrace();52 } finally {53 DB.close(conn);54 DB.close(ps);55 }56 return flag;57 }*/

58 public intcheckUsers(String username ,String password) {59 DButil DB = newDButil();60 String sql="select username,password ,jurisdiction from account where username=? and password=?";61 //String sql = "select username,password,jurisdiction from account where username='"+username+"' and password='"+password+"'";

62 Connection conn = null;63 PreparedStatement ps = null;64 int flag = -1;65 try{66 conn =DB.getConn();67 ps =conn.prepareStatement(sql);68 ps.setString(1, username);69 ps.setString(2, password);70 //ps.setInt(3, jurisdiction);

71 ResultSet rs =ps.executeQuery();72 if(rs.next())73 {74

75 flag=rs.getInt("jurisdiction");76 }77

78 } catch(Exception e) {79

80 flag=-1;81 e.printStackTrace();82 } finally{83 DB.close(conn);84 DB.close(ps);85 }86 returnflag;87 }88

89

90 public booleanaddUser(User user) {91 DButil DB = newDButil();92 String sql = "insert into middle_text(name,sex,nation,time,age,outlook,service) values(?,?,?,?,?,?,?)";93 Connection conn = null;94 PreparedStatement ps = null;95 boolean flag = false;96 int a = 0;97

98 try{99 conn =DB.getConn();100 ps =conn.prepareStatement(sql);101 ps.setString(1, user.getName());102 ps.setString(2, user.getSex());103 ps.setString(3, user.getNation());104 ps.setString(4, user.getTime());105 ps.setString(5, user.getAge());106 ps.setString(6, user.getOutlook());107 ps.setString(7, user.getService());108 a =ps.executeUpdate();109

110 if (a != 0) {111 flag = true;112 }113 } catch(Exception e) {114 System.out.println( "添加失败");115 flag=false;116 e.printStackTrace();117 } finally{118 DB.close(conn);119 DB.close(ps);120 }121 returnflag;122 }123

124

125

126

127

128

129 public booleandeleteUser(String name) {130 DButil DB = newDButil();131 Connection conn = null;132 Statement state = null;133 String sql = "";134 boolean flag = false;135 try{136 conn =DB.getConn();137 sql = "delete from middle_text where name ='" + name + "'";138 state =conn.createStatement();139 int a = 0;140 a =state.executeUpdate(sql);141 if (a != 0) {142 flag = true;143 }144 } catch(Exception e) {145 //TODO: handle exception

146 } finally{147 DB.close(conn);148 DB.close(state);149 }150

151 returnflag;152 }153 //֤

154 /*public boolean loginUser(String userName, String password) {155

156 DButil DB = new DButil();157 boolean flag = false;158 Connection con = null;159 MD5_Salt ms = new MD5_Salt();160 try {161 con = DB.getConn();162 Statement state = con.createStatement();163 ResultSet rs = state.executeQuery("select * from user where username='" + userName + "'");164 if (rs.next()) {165 String dbPassword = rs.getString("dbpassword");166 String salt1 = rs.getString("salt1");167 String salt2 = rs.getString("salt2");168 flag = ms.TF_Password_DBpassword(password, dbPassword, salt1, salt2);169 }170

171 } catch (SQLException e) {172 // TODO �Զ����ɵ� catch ��173 e.printStackTrace();174 }175 return flag;176

177 }*/

178

179 //��������

180 public booleanresetUserPassword(String name,String sex,String outlook,String service) {181

182 DButil DB = newDButil();183 boolean flag = false;184 Connection conn = null;185 Statement state = null;186 int a = 0;187 try{188 String sql="update middle_text set sex='" +sex189 + "',outlook='"+outlook+"',service='"+service+"'where name= '" + name + "'";190 conn =DB.getConn();191 state =conn.createStatement();192 a =state.executeUpdate(sql);193 if (a > 0) {194 flag = true;195 }196

197 } catch(SQLException e) {198 //TODO �Զ����ɵ� catch ��

199 e.printStackTrace();200 }201 returnflag;202

203 }204 /*public boolean searchuser(String username)205 {206 User user=new User();207 DButil DB = new DButil();208 boolean flag = false;209 Connection conn = null;210 Statement state = null;211 int a = 0;212 try {213

214 //"select * from User";215 //select ename ,sal from emp where ename='SMITH';216 String sql="select * from text where username= '"+username+"'";217 //String sql="select password from text where username='" + username + "'";218 conn = DB.getConn();219 state = conn.createStatement();220 ResultSet rs = state.executeQuery(sql);221

222 if (rs != null) {223 while(rs.next()) {224 user.setId(rs.getString("id"));225 user.setUsername(rs.getString("username"));226 user.setPassword(rs.getString("password"));227 }228 System.out.println(user.getPassword());229 flag = true;230

231 }232

233 } catch (SQLException e) {234 // TODO �Զ����ɵ� catch ��235 e.printStackTrace();236 }237 return flag;238

239

240 }*/

241

242 //�޸�����

243 /*public boolean resetUserPassword(String userName, String newPassword) {244

245 DButil DB = new DButil();246 Salt salt = new Salt();247 MD5_Salt ms = new MD5_Salt();248 boolean flag = false;249 Connection conn = null;250 Statement state = null;251 int a = 0;252 try {253 String salt1 = salt.getSalt();254 String salt2 = salt.getSalt();255 String dbPassword = ms.get_MD5Salt(newPassword, salt1, salt2);256 String sql = "update user set dbpassword='" + dbPassword + "', salt1='" + salt1 + "', salt2= '" + salt2257 + "'where username= '" + userName + "'";258

259 conn = DB.getConn();260 state = conn.createStatement();261 a = state.executeUpdate(sql);262 if (a > 0) {263 flag = true;264 }265

266 } catch (SQLException e) {267 // TODO �Զ����ɵ� catch ��268 e.printStackTrace();269 }270 return flag;271 */

272

273 //�鿴���л�Ա

274 /*public List UserList() {275 DButil DB = new DButil();276 String sql = "select * from text ";277 List list = new ArrayList<>();278 Connection conn = null;279 Statement state = null;280 ResultSet rs = null;281

282 try {283 conn = DB.getConn();284 state = conn.createStatement();285 rs = state.executeQuery(sql);286 User user = null;287 while (rs.next()) {288

289 int id2 = rs.getInt("id");290 String userName2 = rs.getString("username");291 // String password2 =rs.getString("password");292 String name2 = rs.getString("name");293 user = new User();294 user.setId(id2);295 user.setUsername(userName2);296 list.add(user);297 }298 } catch (SQLException e) {299 e.printStackTrace();300 } finally {301 DB.close(conn);302 DB.close(state);303 DB.close(rs);304 }305

306 return list;307 }*/

308 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值