┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ 装 ┊ ┊ ┊ ┊ ┊ 订 ┊ ┊ ┊ ┊ ┊ 线 ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊
课程设计纸
7. 具体功能实现
7.1 登录功能的实现
(1) 登录界面该界面可以对用户名和密码进行验证如不正确则会显示错误信息,如图7.1所示:
图7.1 登录界面
(2)登录功能的实现代码,此段代码通过连接数据库用sql语句查找符合条件的用户,返回值为Logininfo类的对象,在调用此方法的程序中验证此对象是否为空,
如为空,则没有该用户显示错误信息;如不为空,则该用户存在,可直接用此对象的getRole()方法进入不同的界面。
public Logininfo querybyUsernameAndPassword(Logininfo user){
Logininfo u =new Logininfo(); String name=user.getName(); String pwd=user.getPassword(); String sql=\+name+\
password='\+pwd+\;
DBConnection conn=new DBConnection(); ResultSet rs=conn.doQuery(sql); try { if(rs.next()){ u.setName(rs.getString(\)); u.setPassword(rs.getString(\)); u.setRole(rs.getInt(\)); } } catch (SQLException e) { e.printStackTrace(); } conn.queryclose(); return u; }
共 39 页 第 15 页
┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ 装 ┊ ┊ ┊ ┊ ┊ 订 ┊ ┊ ┊ ┊ ┊ 线 ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊
课程设计纸
7.2 学生信息查询功能的实现
(1) 学生信息查询功能界面,可通过此界面按多条件查找如可按学号、姓名或班级等查找,如图7.2所示:
图7.2 学生信息查询界面
(2) 学生信息查询功能的实现代码,此代码利用sql语句在数据库中查找所有学生信息,存放在List对象中;如有条件的查找则只需修改sql语句即可,提高了代码的重用性。
public List
List
Studentinfo student = new Studentinfo(); student.setId(rs.getInt(\));
student.setName(rs.getString(\)); student.setClasses(rs.getInt(\)); student.setSex(rs.getString(\)); student.setRace(rs.getString(\)); student.setNativeplace(rs.getString(\)); student.setDepartment(rs.getString(\)); student.setSchoolyear(rs.getString(\)); student.setBirth(rs.getString(\)); list.add(student);
共 39 页 第 16 页
┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ 装 ┊ ┊ ┊ ┊ ┊ 订 ┊ ┊ ┊ ┊ ┊ 线 ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊
课程设计纸
} } catch (SQLException e) { e.printStackTrace(); } conn.queryclose(); return list;}
7.3 学生信息添加功能的实现
(1) 学生信息添加功能界面,此界面可添加学生信息到数据库中,如图7.3
所示:
图7.3 学生信息添加界面
(2) 学生信息添加功能的实现代码,此方法以Studentinfo的对象为参数,省去了传多个参数的麻烦,返回值为布尔型,可直接判断添加操作是否成功。
public boolean insertStudent(Studentinfo student) {
DBConnection conn = new DBConnection(); String name = student.getName(); int classes = student.getClasses(); String sex=student.getSex(); String race=student.getRace(); String nativeplace=student.getNativeplace(); String department=student.getName(); String schoolyear=student.getSchoolyear(); String birth=student.getBirth(); String sql = \
(name,classes,sex,race,nativeplace,department,schoolyear,birth) values('\+ name + \ + classes + \ + sex +
\+race+\+nativeplace+\+department+\+schoolyear+\+birth+\;
int count = conn.Update(sql); if (count > 0) {
共 39 页 第 17 页
┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ 装 ┊ ┊ ┊ ┊ ┊ 订 ┊ ┊ ┊ ┊ ┊ 线 ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊
课程设计纸
}
conn.updateclose(); return true; } else { conn.updateclose(); return false; }
7.4 学生信息修改功能的实现
(1)学生信息修改功能界面,此界面可以修改学生信息,如图7.4所示:
图7.4 学生信息修改界面
(2)学生信息修改功能的实现代码,此方法以Studentinfo的对象为参数,省去了传多个参数的麻烦,返回值为布尔型,可直接判断修改操作是否成功。
public boolean Alteruser(Studentinfo s){ String name=s.getName(); int classes=s.getClasses(); String sex=s.getSex(); String race=s.getRace(); String nativeplace=s.getNativeplace(); String department=s.getDepartment(); String schoolyear=s.getSchoolyear(); String birth=s.getBirth(); DBConnection conn=new DBConnection(); String sql=\
name='\+name+\+classes+\+sex+\+race+\veplace='\+nativeplace+\ + \+department+\ schoolyear='\+schoolyear+\+birth+\+s.getId(); int count=conn.Update(sql); if(count>0){
共 39 页 第 18 页
┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ 装 ┊ ┊ ┊ ┊ ┊ 订 ┊ ┊ ┊ ┊ ┊ 线 ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊ ┊
课程设计纸
}
conn.updateclose(); return true; }else{ conn.updateclose(); return false; }
7.5 学生信息删除功能的实现
(1)学生信息删除功能界面,在查询的结果表上直接选中表中的行,点击删除确定就可删除选中行如图7.5所示:
图7.5 学生信息删除界面
(2)学生信息删除功能的实现代码,此方法的参数(此参数是通过在表中添加的鼠标监听器得到的)是所选的表中行的信息的学号,返回布尔型的值,可判断删除是否成功。
}
public boolean deletebyID(int id){
DBConnection conn=new DBConnection();
String sql=\ + id; int count=conn.Update(sql); if(count>0){ conn.updateclose(); return true; }else{ conn.updateclose(); return false; }
共 39 页 第 19 页
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库学生成绩管理系统Java课程设计(4)在线全文阅读。
相关推荐: