赞
踩
1 packagecom.epoint.Dao.Impl;2
3 importjava.sql.Connection;4 importjava.sql.PreparedStatement;5 importjava.sql.ResultSet;6
7 importcom.epoint.Dao.ManagerDao;8 importcom.epoint.model.Course;9 importcom.epoint.model.Manager;10 importcom.epoint.model.User;11 importcom.epoint.utils.BaseDao;12
13 public class ManagerDaoImpl implementsManagerDao{14 //管理员登录
15 @Override16 publicManager login(Manager manager) {17 //TODO Auto-generated method stub
18 Connection con = null;19 PreparedStatement ps= null;20 ResultSet rs=null;21 try{22 con=BaseDao.getCon();23 String sql="select * from manager where m_name=? and m_password=?";24 ps=con.prepareStatement(sql);25 ps.setString(1, manager.getM_name());26 ps.setString(2, manager.getM_password());27 rs=ps.executeQuery();28 Manager managers=null;29 if(rs.next()){30 managers=newManager();31 managers.setM_name(rs.getString("m_name"));32 managers.setM_password(rs.getString("m_password"));33 returnmanagers;34
35 }36 else
37 return null;38
39 } catch(Exception e) {40 //TODO Auto-generated catch block
41 e.printStackTrace();42 }43
44 return null;45 }46 //添加课程
47 @Override48 public voidaddCourse(Course course) {49 //TODO Auto-generated method stub
50 Connection con = null;51 PreparedStatement ps= null;52 ResultSet rs=null;53 try{54 con=BaseDao.getCon();55 String sql="insert into course (c_id,c_name,teacher) values(?,?,?)";56 ps=con.prepareStatement(sql);57 ps.setString(1, course.getC_id());58 ps.setString(2, course.getC_name());59 ps.setString(3, course.getTeacher());60 int a =ps.executeUpdate();61 } catch(Exception e) {62 //TODO Auto-generated catch block
63 e.printStackTrace();64 }65
66 }67 //删除课程
68 @Override69 public voiddeleteCourse(String c_id) {70 //TODO Auto-generated method stub
71 Connection con = null;72 PreparedStatement ps= null;73 ResultSet rs=null;74 try{75 con=BaseDao.getCon();76 String sql = "delete from course where c_id=?";77 ps=con.prepareStatement(sql);78 ps.setString(1, c_id);79 int a=ps.executeUpdate();80 if(a>0){81 System.out.println("删除成功");82 String sql2="delete from user_course where c_id=?";83 ps=con.prepareStatement(sql2);84 ps.setString(1, c_id);85 int b=ps.executeUpdate();86 }87 else{88 System.out.println("输入ID有误,删除失败");89 }90 }catch(Exception e) {91 //TODO Auto-generated catch block
92 e.printStackTrace();93 }94
95 }96 //修改课程
97 @Override98 public voidupdateCourse(Course course) {99 //TODO Auto-generated method stub
100 Connection con = null;101 PreparedStatement ps= null;102 ResultSet rs=null;103 try{104 con=BaseDao.getCon();105 String sql="update course set c_name=?,teacher=? where c_id=?";106 ps=con.prepareStatement(sql);107 ps.setString(1, course.getC_name());108 ps.setString(2, course.getTeacher());109 ps.setString(3, course.getC_id());110 int a =ps.executeUpdate();111 if(a>0){112 System.out.println("课程修改成功");113 }114 else{115 System.out.println("输入ID有误,课程修改失败");116 }117
118 } catch(Exception e) {119 //TODO Auto-generated catch block
120 e.printStackTrace();121 }122
123 }124 //查看某一课程
125 @Override126 public voidselectOneCourse(String c_id) {127 //TODO Auto-generated method stub
128 Connection con = null;129 PreparedStatement ps= null;130 ResultSet rs=null;131 try{132 con=BaseDao.getCon();133 String sql ="select * from course where c_id=?";134 ps=con.prepareStatement(sql);135 ps.setString(1, c_id);136 rs=ps.executeQuery();137 Course course=null;138 if(rs.next()){139 course = newCourse();140 course.setC_id(rs.getString("c_id"));141 course.setC_name(rs.getString("c_name"));142 course.setTeacher(rs.getString("teacher"));143 System.out.println(course.getC_id()+" "+course.getC_name()+" "+course.getTeacher());144 }145 } catch(Exception e) {146 //TODO Auto-generated catch block
147 e.printStackTrace();148 }149 }150 //查看全部课程
151 @Override152 public voidselectAllCourse() {153 //TODO Auto-generated method stub
154 Connection con = null;155 PreparedStatement ps= null;156 ResultSet rs=null;157 try{158 con=BaseDao.getCon();159 String sql ="select * from course ";160 ps=con.prepareStatement(sql);161 rs=ps.executeQuery();162 Course course=null;163 while(rs.next()){164 course = newCourse();165 course.setC_id(rs.getString("c_id"));166 course.setC_name(rs.getString("c_name"));167 course.setTeacher(rs.getString("teacher"));168 System.out.println(course.getC_id()+" "+course.getC_name()+" "+course.getTeacher());169 }170 } catch(Exception e) {171 //TODO Auto-generated catch block
172 e.printStackTrace();173 }174
175 }176 //添加学生
177 @Override178 public voidaddUser(User user) {179 //TODO Auto-generated method stub
180 Connection con = null;181 PreparedStatement ps= null;182 ResultSet rs=null;183 try{184 con=BaseDao.getCon();185 String sql="insert into user (username,password) values(?,?)";186 ps=con.prepareStatement(sql);187 ps.setString(1, user.getUsername());188 ps.setString(2, user.getPassword());189 int a =ps.executeUpdate();190 if(a>0){191 System.out.println("学生添加成功");192 }193 else{194 System.out.println("学生添加失败");195 }196 } catch(Exception e) {197 //TODO Auto-generated catch block
198 e.printStackTrace();199 }200 }201 //删除学生
202 @Override203 public voiddeleteUser(String username) {204 //TODO Auto-generated method stub
205 Connection con = null;206 PreparedStatement ps= null;207 ResultSet rs=null;208 try{209 con=BaseDao.getCon();210 String sql = "delete from user where username=?";211 ps=con.prepareStatement(sql);212 ps.setString(1, username);213 int a=ps.executeUpdate();214 if(a>0){215 System.out.println("删除成功");216 String sql2="delete from user_course where username=?";217 ps=con.prepareStatement(sql2);218 ps.setString(1, username);219 int b=ps.executeUpdate();220 }221 else{222 System.out.println("输入用户名有误,删除失败");223 }224 }catch(Exception e) {225 //TODO Auto-generated catch block
226 e.printStackTrace();227 }228 }229 //修改用户
230 @Override231 public voidupdateUser(User user) {232 //TODO Auto-generated method stub
233 Connection con = null;234 PreparedStatement ps= null;235 ResultSet rs=null;236 try{237 con=BaseDao.getCon();238 String sql="update user set password=? where username=?";239 ps=con.prepareStatement(sql);240 ps.setString(1, user.getPassword());241 ps.setString(2, user.getUsername());242 int a =ps.executeUpdate();243 if(a>0){244 System.out.println("用户修改成功");245 }246 else{247 System.out.println("输入有误,用户修改失败");248 }249
250 } catch(Exception e) {251 //TODO Auto-generated catch block
252 e.printStackTrace();253 }254 }255 //查看某一学生
256 @Override257 public voidselectOneUser(String username) {258 //TODO Auto-generated method stub
259 Connection con = null;260 PreparedStatement ps= null;261 ResultSet rs=null;262 try{263 con=BaseDao.getCon();264 String sql ="select * from user where username=?";265 ps=con.prepareStatement(sql);266 ps.setString(1, username);267 rs=ps.executeQuery();268 User user=null;269 if(rs.next()){270 user = newUser();271 user.setUsername(rs.getString("username"));272 user.setPassword(rs.getString("password"));273 System.out.println(user.getUsername()+" "+user.getPassword());274 }275 } catch(Exception e) {276 //TODO Auto-generated catch block
277 e.printStackTrace();278 }279 }280 //查看全部课程
281 @Override282 public voidselectAllUser() {283 //TODO Auto-generated method stub
284 Connection con = null;285 PreparedStatement ps= null;286 ResultSet rs=null;287 try{288 con=BaseDao.getCon();289 String sql ="select * from user ";290 ps=con.prepareStatement(sql);291 rs=ps.executeQuery();292 User user=null;293 while(rs.next()){294 user = newUser();295 user.setUsername(rs.getString("username"));296 user.setPassword(rs.getString("password"));297 System.out.println(user.getUsername()+" "+user.getPassword());298 }299 } catch(Exception e) {300 //TODO Auto-generated catch block
301 e.printStackTrace();302 }303 }304
305 }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。