欢迎来到天天文库
浏览记录
ID:9387971
大小:198.80 KB
页数:12页
时间:2018-04-29
《java jdbc小项目《学生管理系统》源码带注解》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Java+javabean+JDBC学生管理系统一、项目结构本项目是使用javabean和jdbc做的,这个包是实体包这个是菜单包,源码不会再发这些,自己写就好了。二、项目运行结果一、源码废话不多说,直接上源码:这两个是关键源码,是负责登录和学生信息操作的逻辑类:publicclassAdminDaoImplextendsDBHelperimplementsAdminDao{Adminadmin=null;/***登录*/@SuppressWarnings("resource")@OverridepublicAdminlogin(Stringname){Stringsql="selec
2、t*fromadminwhereusername=?";Object[]param={name};Objectobj=this.excute(sql,param);ResultSetrs=(ResultSet)obj;try{while(rs.next()){admin=newAdmin();Stringusername=rs.getString("username");Stringpassword=rs.getString("password");admin.setUsername(username);admin.setPassword(password);}}catch(SQLEx
3、ceptione){System.out.println("未找到此name");}returnadmin;}}publicclassStudentDaoImplextendsDBHelperimplementsStudentDao{Studentstu=null;Listlist=null;@SuppressWarnings("resource")@OverridepublicStudentgetInfoByid(intid){Stringsql="select*fromstudentwhereid=?";Object[]param={id};Objectobj=t
4、his.excute(sql,param);ResultSetrs=(ResultSet)obj;stu=newStudent();try{while(rs.next()){stu.setId(rs.getInt("id"));stu.setName(rs.getString("name"));stu.setAge(rs.getInt("age"));stu.setGender(rs.getString("gender"));stu.setGrade(rs.getString("grade"));stu.setPhone(rs.getLong("phone"));stu.setEmai
5、l(rs.getString("email"));stu.setAddress(rs.getString("address"));}}catch(SQLExceptione){e.printStackTrace();}finally{this.closeAll();}returnstu;}@SuppressWarnings("resource")@OverridepublicListgetAllStu(){Stringsql="select*fromstudent";Objectobj=this.excute(sql,null);ResultSetrs=(Result
6、Set)obj;list=newArrayList();try{while(rs.next()){stu=newStudent();stu.setId(rs.getInt("id"));stu.setName(rs.getString("name"));stu.setAge(rs.getInt("age"));stu.setGender(rs.getString("gender"));stu.setGrade(rs.getString("grade"));stu.setPhone(rs.getLong("phone"));stu.setEmail(rs.getStri
7、ng("email"));stu.setAddress(rs.getString("address"));list.add(stu);}}catch(SQLExceptione){e.printStackTrace();}finally{this.closeAll();}returnlist;}@SuppressWarnings("resource")@OverridepublicStringgetNameById(intid){Stringn
此文档下载收益归作者所有