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