學(xué)生成績管理系統(tǒng)Java課程設(shè)計(jì)_第1頁
學(xué)生成績管理系統(tǒng)Java課程設(shè)計(jì)_第2頁
學(xué)生成績管理系統(tǒng)Java課程設(shè)計(jì)_第3頁
學(xué)生成績管理系統(tǒng)Java課程設(shè)計(jì)_第4頁
學(xué)生成績管理系統(tǒng)Java課程設(shè)計(jì)_第5頁
已閱讀5頁,還剩36頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

┊┊┊┊┊┊┊┊┊┊┊┊┊裝┊┊┊┊┊訂┊┊┊┊┊線┊┊┊┊┊┊┊┊┊┊┊┊┊課程設(shè)計(jì)紙共39頁第頁學(xué)生成績t_grade表結(jié)構(gòu)定義,如圖6.3所示:圖6.3學(xué)生成績表結(jié)構(gòu)定義圖(4)班級(jí)成績t_tongji表結(jié)構(gòu)定義,如圖6.4所示:圖6.4班級(jí)成績表結(jié)構(gòu)定義圖7.具體功能實(shí)現(xiàn)7.1登錄功能的實(shí)現(xiàn)(1)登錄界面該界面可以對(duì)用戶名和密碼進(jìn)行驗(yàn)證如不正確則會(huì)顯示錯(cuò)誤信息,如圖7.1所示:圖7.1登錄界面(2)登錄功能的實(shí)現(xiàn)代碼,此段代碼通過連接數(shù)據(jù)庫用sql語句查找符合條件的用戶,返回值為Logininfo類的對(duì)象,在調(diào)用此方法的程序中驗(yàn)證此對(duì)象是否為空,如為空,則沒有該用戶顯示錯(cuò)誤信息;如不為空,則該用戶存在,可直接用此對(duì)象的getRole()方法進(jìn)入不同的界面。publicLogininfoquerybyUsernameAndPassword(Logininfouser){ Logininfou=newLogininfo(); Stringname=user.getName(); Stringpwd=user.getPassword(); Stringsql="select*fromt_loginwherename='"+name+"'andpassword='"+pwd+"'"; DBConnectionconn=newDBConnection(); ResultSetrs=conn.doQuery(sql); try{ if(rs.next()){ u.setName(rs.getString("name")); u.setPassword(rs.getString("password")); u.setRole(rs.getInt("role")); } }catch(SQLExceptione){ e.printStackTrace(); } conn.queryclose(); returnu; }7.2學(xué)生信息查詢功能的實(shí)現(xiàn)(1)學(xué)生信息查詢功能界面,可通過此界面按多條件查找如可按學(xué)號(hào)、姓名或班級(jí)等查找,如圖7.2所示:圖7.2學(xué)生信息查詢界面(2)學(xué)生信息查詢功能的實(shí)現(xiàn)代碼,此代碼利用sql語句在數(shù)據(jù)庫中查找所有學(xué)生信息,存放在List對(duì)象中;如有條件的查找則只需修改sql語句即可,提高了代碼的重用性。publicList<Studentinfo>queryAll(){ DBConnectionconn=newDBConnection(); Stringsql="select*fromt_studentinfo"; ResultSetrs=conn.doQuery(sql); List<Studentinfo>list=newArrayList<Studentinfo>(); try{ while(rs.next()){ Studentinfostudent=newStudentinfo(); student.setId(rs.getInt("id")); student.setName(rs.getString("name")); student.setClasses(rs.getInt("classes")); student.setSex(rs.getString("sex")); student.setRace(rs.getString("race")); student.setNativeplace(rs.getString("nativeplace")); student.setDepartment(rs.getString("department")); student.setSchoolyear(rs.getString("schoolyear")); student.setBirth(rs.getString("birth")); list.add(student); } }catch(SQLExceptione){ e.printStackTrace(); } conn.queryclose(); returnlist;}7.3學(xué)生信息添加功能的實(shí)現(xiàn)(1)學(xué)生信息添加功能界面,此界面可添加學(xué)生信息到數(shù)據(jù)庫中,如圖7.3所示:圖7.3學(xué)生信息添加界面(2)學(xué)生信息添加功能的實(shí)現(xiàn)代碼,此方法以Studentinfo的對(duì)象為參數(shù),省去了傳多個(gè)參數(shù)的麻煩,返回值為布爾型,可直接判斷添加操作是否成功。publicbooleaninsertStudent(Studentinfostudent){ DBConnectionconn=newDBConnection(); Stringname=student.getName(); intclasses=student.getClasses(); Stringsex=student.getSex(); Stringrace=student.getRace(); Stringnativeplace=student.getNativeplace(); Stringdepartment=student.getName(); Stringschoolyear=student.getSchoolyear(); Stringbirth=student.getBirth(); Stringsql="insertintot_studentinfo(name,classes,sex,race,nativeplace,department,schoolyear,birth)values('"+name+"',"+classes+",'"+sex+"','"+race+"','"+nativeplace+"','"+department+"','"+schoolyear+"','"+birth+"')"; intcount=conn.Update(sql); if(count>0){ conn.updateclose(); returntrue; }else{ conn.updateclose(); returnfalse; } }7.4學(xué)生信息修改功能的實(shí)現(xiàn)(1)學(xué)生信息修改功能界面,此界面可以修改學(xué)生信息,如圖7.4所示: 圖7.4學(xué)生信息修改界面(2)學(xué)生信息修改功能的實(shí)現(xiàn)代碼,此方法以Studentinfo的對(duì)象為參數(shù),省去了傳多個(gè)參數(shù)的麻煩,返回值為布爾型,可直接判斷修改操作是否成功。publicbooleanAlteruser(Studentinfos){ Stringname=s.getName(); intclasses=s.getClasses(); Stringsex=s.getSex(); Stringrace=s.getRace(); Stringnativeplace=s.getNativeplace(); Stringdepartment=s.getDepartment(); Stringschoolyear=s.getSchoolyear(); Stringbirth=s.getBirth(); DBConnectionconn=newDBConnection(); Stringsql="updatet_studentinfosetname='"+name+"',classes="+classes+",sex='"+sex+"',race='"+race+"',nativeplace='"+nativeplace+"',"+ "department='"+department+"', schoolyear='"+schoolyear+"',birth='"+birth+"'whereid="+s.getId(); intcount=conn.Update(sql); if(count>0){ conn.updateclose(); returntrue; }else{ conn.updateclose(); returnfalse; }}7.5學(xué)生信息刪除功能的實(shí)現(xiàn)(1)學(xué)生信息刪除功能界面,在查詢的結(jié)果表上直接選中表中的行,點(diǎn)擊刪除確定就可刪除選中行如圖7.5所示:圖7.5學(xué)生信息刪除界面(2)學(xué)生信息刪除功能的實(shí)現(xiàn)代碼,此方法的參數(shù)(此參數(shù)是通過在表中添加的鼠標(biāo)監(jiān)聽器得到的)是所選的表中行的信息的學(xué)號(hào),返回布爾型的值,可判斷刪除是否成功。publicbooleandeletebyID(intid){ DBConnectionconn=newDBConnection(); Stringsql="deletefromt_studentinfowhereid="+id; intcount=conn.Update(sql); if(count>0){ conn.updateclose(); returntrue; }else{ conn.updateclose(); returnfalse; } }7.6學(xué)生成績查詢功能的實(shí)現(xiàn)(1)學(xué)生成績查詢功能界面,可多條件查詢學(xué)生成績,如圖7.6所示:圖7.6學(xué)生成績查詢功能界面(2)學(xué)生成績查詢功能的實(shí)現(xiàn)代碼,此方法將查到的結(jié)果集中的屬性放到Grade對(duì)象的相應(yīng)字段中(用Grade類中的get()方法實(shí)現(xiàn)),再用while循環(huán)將Grade對(duì)象放入到List中。publicList<Grade>queryAll(){ DBConnectionconn=newDBConnection(); Stringsql="select*fromt_grade"; ResultSetrs=conn.doQuery(sql); List<Grade>list=newArrayList<Grade>(); try{ while(rs.next()){ Gradegrade=newGrade(); grade.setId(rs.getInt("id")); grade.setName(rs.getString("name")); grade.setDepartment(rs.getString("department")); grade.setClasses(rs.getInt("classes")); grade.setEnglish(rs.getFloat("english")); grade.setSoft(rs.getFloat("soft")); grade.setOs(rs.getFloat("os")); grade.setJava(rs.getFloat("Java")); grade.setSum(rs.getFloat("sum")); grade.setAverage(rs.getFloat("average")); grade.setDates(rs.getString("dates")); list.add(grade); } }catch(SQLExceptione){ e.printStackTrace(); } conn.queryclose(); returnlist; }7.7學(xué)生成績添加功能的實(shí)現(xiàn)(1)學(xué)生成績添加功能界面,此界面可以添加學(xué)生成績,如圖7.7所示:圖7.7學(xué)生成績添加界面(2)學(xué)生成績添加功能的實(shí)現(xiàn)代碼,傳Grade對(duì)象參數(shù),返回布爾值,方便判斷。publicbooleaninsertGrade(Gradegrade){ DBConnectionconn=newDBConnection(); Stringname=grade.getName(); Stringdepartment=grade.getDepartment(); intclasses=grade.getClasses(); floatenglish=grade.getEnglish(); floatsoft=grade.getSoft(); floatos=grade.getOs(); floatjava=grade.getJava(); floatsum=grade.getSum(); floataverage=grade.getAverage(); Stringdates=grade.getDates(); Stringsql="insertintot_grade(name,department,classes,English,soft,os,Java,sum,average,dates)values('" +name+"','"+department+"',"+classes+","+english+","+soft+","+os+","+java+","+sum+","+average+",'"+dates+"')"; intcount=conn.Update(sql); if(count>0){ conn.updateclose(); returntrue; }else{ conn.updateclose(); returnfalse; } }7.8學(xué)生成績修改功能的實(shí)現(xiàn)(1)學(xué)生成績修改功能界面,此界面只可以更改分?jǐn)?shù)不可以更改其他信息,這樣避免了對(duì)學(xué)生信息更改的混亂,如圖7.8所示:圖7.8學(xué)生成績修改界面(2)學(xué)生成績修改功能的實(shí)現(xiàn)代碼,此方法運(yùn)用的技術(shù)同添加方法相同。publicbooleanAlterGrade(Gradeg){ floatenglish=g.getEnglish(); floatsoft=g.getSoft(); floatos=g.getOs(); floatjava=g.getJava(); floatsum=english+soft+os+java; floataverage=sum/4; DBConnectionconn=newDBConnection();Stringsql="updatet_gradesetEnglish="+english+",soft="+soft+",os="+os+",Java="+java+",sum="+sum+",average="+average+"whereid="+g.getId(); intcount=conn.Update(sql); if(count>0){ conn.updateclose(); returntrue; }else{ conn.updateclose(); returnfalse; } }7.9學(xué)生成績導(dǎo)出功能的實(shí)現(xiàn) (1)學(xué)生成績導(dǎo)出功能界面,此界面可以再選位置創(chuàng)建一個(gè)新的文本文檔,將表中的內(nèi)容存放到此文本文檔中,如圖7.9所示:圖7.9學(xué)生成績導(dǎo)出功能界面(2)學(xué)生成績導(dǎo)出功能的實(shí)現(xiàn)代碼,此段代碼運(yùn)用了File類和BufferedWtiter類來實(shí)現(xiàn)文件的創(chuàng)建與寫出(從內(nèi)存寫到外存)。GradeDaodata=newGradeDao();Listlist=data.queryAll();GradeTabletable=newGradeTable();JTabletable1=newJTable();table1=table.GradeTable(table1,list);intp=fileDialog.showSaveDialog(this);Filefile=fileDialog.getSelectedFile();Strings="學(xué)號(hào)"+"姓名"+"院系"+"班級(jí)"+"英語"+"軟件工程"+"操縱系統(tǒng)"+"Java"+"總成績"+"平均成績"+"日期"+"\n"; try{ FileWriterwrite=newFileWriter(file); BufferedWriterwrite1=newBufferedWriter(write);//從內(nèi)存寫出到硬盤 write1.write(s); write1.newLine(); for(inti=0;i<list.size();i++){ Gradeg=newGrade(); g=(Grade)list.get(i); Strings1=""+g.getId()+""+g.getName()+""+g.getDepartment()+""+g.getClasses()+""+g.getEnglish()+""+g.getSoft()+""+g.getOs()+""+g.getJava()+""+g.getSum()+""+g.getAverage()+""+g.getDates()+"\n";System.out.println(s1);//從內(nèi)存寫出到硬盤 write1.write(s1);write1.newLine();}write1.close();write.close(); }catch(IOExceptiona){ }7.10班級(jí)成績查詢功能的實(shí)現(xiàn) (1)班級(jí)成績查詢功能界面,此界面可以多條件查詢班級(jí)成績,如圖7.10所示:圖7.10班級(jí)成績查詢界面(2)班級(jí)成績查詢功能的實(shí)現(xiàn)代碼,此方法將查到的結(jié)果集中的屬性放到Tongji對(duì)象的相應(yīng)字段中(用Tongji類中的get()方法實(shí)現(xiàn)),再用while循環(huán)將Tongji對(duì)象放入到List中,運(yùn)用list對(duì)象更方便操作。publicList<Tongji>queryAll(){ DBConnectionconn=newDBConnection(); Stringsql="select*fromt_tongji"; ResultSetrs=conn.doQuery(sql); List<Tongji>list=newArrayList<Tongji>(); try{ while(rs.next()){ Tongjit=newTongji(); t.setId(rs.getInt("id")); t.setClasses(rs.getInt("classes")); t.setSum(rs.getFloat("sum")); t.setAverage(rs.getFloat("average")); t.setDates(rs.getString("dates")); list.add(t); } }catch(SQLExceptione){ e.printStackTrace(); } conn.queryclose(); returnlist; }8.總結(jié)經(jīng)過四個(gè)多星期的系統(tǒng)設(shè)計(jì)與代碼編寫,基本完成了學(xué)生成績管理系統(tǒng)(主要是權(quán)限分配、學(xué)生信息管理、學(xué)生成績管理、班級(jí)成績管理)的設(shè)計(jì)與實(shí)現(xiàn)。在這個(gè)系統(tǒng)中,可實(shí)現(xiàn)由計(jì)算機(jī)代替人工執(zhí)行一系列諸如學(xué)生信息、學(xué)生成績和班級(jí)成績信息的增、刪、查、改和導(dǎo)出等操作以及個(gè)人信息的更新等等,這樣就使管理人員從繁重的工作中解脫出來,同時(shí)實(shí)現(xiàn)管理工作的規(guī)范化、效率化、國際化。在設(shè)計(jì)過程中,我首先考慮到了本系統(tǒng)各個(gè)大的功能模塊,然后進(jìn)行更加詳細(xì)的劃分,逐步完善各個(gè)模塊的具體內(nèi)容。在進(jìn)行具體代碼的編寫時(shí),突然會(huì)發(fā)現(xiàn)有很多邊界條件沒有考慮到,各種各樣的漏洞導(dǎo)致系統(tǒng)容易崩潰不能正常運(yùn)行,這就需要補(bǔ)充很多的邊界控制條件,這時(shí)才明白寫出能運(yùn)行的程序和寫出健壯的程序是完全不同的兩個(gè)概念,這些都是需要牢記和掌握的。在信息提示方面,需要給用戶一些溫馨的提示,而不是諸如“錯(cuò)誤編號(hào)0x704820”9.附錄(1)bean包/*bean包中的Logininfo類*/packagebean;publicclassLogininfo{ intid; Stringname; Stringpassword; introle; publicintgetId(){ returnid; } publicvoidsetId(intid){ this.id=id; } publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ =name; } publicStringgetPassword(){ returnpassword; } publicvoidsetPassword(Stringpassword){ this.password=password; } publicintgetRole(){ returnrole; } publicvoidsetRole(introle){ this.role=role; } }/*bean包中的Studentinfo類*/packagebean;publicclassStudentinfo{ privateintid; privateStringname; privateintclasses; privateStringsex; privateStringrace; privateStringnativeplace; privateStringdepartment; privateStringschoolyear; privateStringbirth; publicintgetId(){ returnid; } publicvoidsetId(intid){ this.id=id; } publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ =name; } publicintgetClasses(){ returnclasses; } publicvoidsetClasses(intclasses){ this.classes=classes; } publicStringgetSex(){ returnsex; } publicvoidsetSex(Stringsex){ this.sex=sex; } publicStringgetRace(){ returnrace; } publicvoidsetRace(Stringrace){ this.race=race; } publicStringgetNativeplace(){ returnnativeplace; } publicvoidsetNativeplace(Stringnativeplace){ this.nativeplace=nativeplace; } publicStringgetDepartment(){ returndepartment; } publicvoidsetDepartment(Stringdepartment){ this.department=department; } publicStringgetSchoolyear(){ returnschoolyear; } publicvoidsetSchoolyear(Stringschoolyear){ this.schoolyear=schoolyear; } publicStringgetBirth(){ returnbirth; } publicvoidsetBirth(Stringbirth){ this.birth=birth; }}/*bean包中的Grade類*/packagebean;publicclassGrade{ privateintid; privateStringname; privateintclasses; privateStringdepartment; privatefloatEnglish; privatefloatsoft; privatefloatos; privatefloatJava; privatefloatsum; privatefloataverage; privateStringdates; publicStringgetDepartment(){ returndepartment; } publicvoidsetDepartment(Stringdepartment){ this.department=department; } publicintgetId(){ returnid; } publicvoidsetId(intid){ this.id=id; } publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ =name; } publicintgetClasses(){ returnclasses; } publicvoidsetClasses(intclasses){ this.classes=classes; } publicfloatgetEnglish(){ returnEnglish; } publicvoidsetEnglish(floatenglish){ English=english; } publicfloatgetSoft(){ returnsoft; } publicvoidsetSoft(floatsoft){ this.soft=soft; } publicfloatgetOs(){ returnos; } publicvoidsetOs(floatos){ this.os=os; } publicfloatgetJava(){ returnJava; } publicvoidsetJava(floatjava){ Java=java; } publicfloatgetSum(){ returnsum; } publicvoidsetSum(floatsum){ this.sum=sum; } publicfloatgetAverage(){ returnaverage; } publicvoidsetAverage(floataverage){ this.average=average; } publicStringgetDates(){ returndates; } publicvoidsetDates(Stringdates){ this.dates=dates; }}/*bean包中的Tongji類*/packagebean;publicclassTongji{ privateintid; privateintclasses; privatefloatsum; privatefloataverage; privateStringdates; publicintgetId(){ returnid; } publicvoidsetId(intid){ this.id=id; } publicintgetClasses(){ returnclasses; } publicvoidsetClasses(intclasses){ this.classes=classes; } publicfloatgetSum(){ returnsum; } publicvoidsetSum(floatsum){ this.sum=sum; } publicfloatgetAverage(){ returnaverage; } publicvoidsetAverage(floataverage){ this.average=average; } publicStringgetDates(){ returndates; } publicvoidsetDates(Stringdatesl){ this.dates=dates; }}(2)jdbc包/*jdbc包中的DBConnection類*/packagejdbc;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassDBConnection{ privateResultSetrs; privateConnectioncon; privateStatementst;static{ try{ Class.forName("com.mysql.jdbc.Driver");//加載驅(qū)動(dòng) }catch(ClassNotFoundExceptione){ e.printStackTrace(); }}publicvoidgetConnection(){ try{ con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","root");//連接數(shù)據(jù)庫語句 }catch(SQLExceptione){ e.printStackTrace(); }}/*查詢數(shù)據(jù)庫*/publicResultSetdoQuery(Stringsql){ this.getConnection(); try{ st=con.createStatement();//用連接創(chuàng)建sql執(zhí)行語句 rs=st.executeQuery(sql);//用sql的執(zhí)行語句調(diào)用executeQuery返回結(jié)果集對(duì)象 }catch(SQLExceptione){ e.printStackTrace(); } returnrs;}/*關(guān)閉數(shù)據(jù)庫連接*/publicvoidqueryclose(){ try{ rs.close(); st.close(); con.close(); }catch(SQLExceptione){ e.printStackTrace(); } }/*更新數(shù)據(jù)庫,返回的本次操作影響的數(shù)據(jù)庫的行數(shù)*/publicintUpdate(Stringsql){ this.getConnection(); intcount=0; try{ st=con.createStatement(); count=st.executeUpdate(sql); }catch(SQLExceptione){ e.printStackTrace(); } returncount;}/*關(guān)閉數(shù)據(jù)庫更新連接*/publicvoidupdateclose(){ try{ st.close(); con.close(); }catch(SQLExceptione){ e.printStackTrace(); }}}(3)dao包/*dao包中的Logindao類*/packagedao;importjava.sql.ResultSet;importjava.sql.SQLException;importjdbc.DBConnection;importbean.Logininfo;/*按用戶名和密碼查詢用戶*/publicclassLogindao{ publicstaticLogininfoquerybyUsernameAndPassword(Logininfouser){ Logininfou=newLogininfo(); Stringname=user.getName(); Stringpwd=user.getPassword(); Stringsql="select*fromt_loginwherename='"+name+"'andpassword='"+pwd+"'"; DBConnectionconn=newDBConnection(); ResultSetrs=conn.doQuery(sql); try{ if(rs.next()){ u.setName(rs.getString("name")); u.setPassword(rs.getString("password")); u.setRole(rs.getInt("role")); } }catch(SQLExceptione){ e.printStackTrace(); } conn.queryclose(); returnu; }}/*dao包中的Studentinfodao類*/packagedao;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.List;importjavax.swing.JTable;importjavax.swing.table.DefaultTableModel;importjdbc.DBConnection;importbean.Logininfo;importbean.Studentinfo;publicclassStudentinfodao{/*查詢所有學(xué)生信息的方法*/ publicList<Studentinfo>queryAll(){ DBConnectionconn=newDBConnection(); Stringsql="select*fromt_studentinfo"; ResultSetrs=conn.doQuery(sql); List<Studentinfo>list=newArrayList<Studentinfo>(); try{ while(rs.next()){ Studentinfostudent=newStudentinfo();//將數(shù)據(jù)庫的信息獲取并放到student中再將student依次加入到list中 student.setId(rs.getInt("id")); student.setName(rs.getString("name")); student.setClasses(rs.getInt("classes")); student.setSex(rs.getString("sex")); student.setRace(rs.getString("race")); student.setNativeplace(rs.getString("nativeplace")); student.setDepartment(rs.getString("department")); student.setSchoolyear(rs.getString("schoolyear")); student.setBirth(rs.getString("birth")); list.add(student); } }catch(SQLExceptione){ e.printStackTrace(); } conn.queryclose(); returnlist; } /*添加學(xué)生信息的方法*/ publicbooleaninsertStudent(Studentinfostudent){ DBConnectionconn=newDBConnection(); Stringname=student.getName(); intclasses=student.getClasses(); Stringsex=student.getSex(); Stringrace=student.getRace(); Stringnativeplace=student.getNativeplace(); Stringdepartment=student.getName(); Stringschoolyear=student.getSchoolyear(); Stringbirth=student.getBirth(); Stringsql="insertintot_studentinfo(name,classes,sex,race,nativeplace,department,schoolyear,birth)values('"+name+"',"+classes+",'"+sex+"','"+race+"','"+nativeplace+"','"+department+"','"+schoolyear+"','"+birth+"')"; intcount=conn.Update(sql); if(count>0){ conn.updateclose(); returntrue; }else{ conn.updateclose(); returnfalse; } } /*按學(xué)號(hào)刪除學(xué)生信息的方法*/ publicbooleandeletebyID(intid){ DBConnectionconn=newDBConnection(); Stringsql="deletefromt_studentinfowhereid="+id; intcount=conn.Update(sql); if(count>0){ conn.updateclose(); returntrue; }else{ conn.updateclose(); returnfalse; } } /*修改學(xué)生信息的方法*/ publicbooleanAlteruser(Studentinfos){ Stringname=s.getName(); intclasses=s.getClasses(); Stringsex=s.getSex(); Stringrace=s.getRace(); Stringnativeplace=s.getNativeplace(); Stringdepartment=s.getDepartment(); Stringschoolyear=s.getSchoolyear(); Stringbirth=s.getBirth(); DBConnectionconn=newDBConnection(); Stringsql="updatet_studentinfosetname='"+name+"',classes="+classes+",sex='"+sex+"',race='"+race+"',nativeplace='"+nativeplace+"',"+"department='"+department+"',schoolyear='"+schoolyear+"',birth='"+birth+"'whereid="+s.getId(); intcount=conn.Update(sql); if(count>0){ conn.updateclose(); returntrue; }else{ conn.updateclose(); returnfalse; } } /*按學(xué)號(hào)查詢學(xué)生信息的方法*/ publicStudentinfoquerybyId(intid){ Studentinfos=newStudentinfo(); Stringsql="select*fromt_studentinfowhereid="+id+""; DBConnectionconn=newDBConnection(); ResultSetrs=conn.doQuery(sql); try{ if(rs.next()){ s.setId(rs.getInt("id")); s.setName(rs.getString("name")); s.setClasses(rs.getInt("classes")); s.setSex(rs.getString("sex")); s.setRace(rs.getString("race")); s.setNativeplace(rs.getString("nativeplace")); s.setDepartment(rs.getString("department")); s.setSchoolyear(rs.getString("schoolyear")); s.setBirth(rs.getString("birth")); } }catch(SQLExceptione){ e.printStackTrace(); } conn.queryclose(); returns; }}/*dao包中的GradeDao類*/packagedao;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.util.ArrayList;importjava.util.List;importjdbc.DBConnection;importbean.Grade;publicclassGradeDao{/*學(xué)生成績查詢方法*/ publicList<Grade>queryAll(){ DBConnectionconn=newDBConnection(); Stringsql="select*fromt_grade"; ResultSetrs=conn.doQuery(sql); List<Grade>list=newArrayList<Grade>(); try{ while(rs.next()){ Gradegrade=newGrade();//將數(shù)據(jù)庫的信息獲取并放到grade中再將grade依次加入到list中 grade.setId(rs.getInt("id")); grade.setName(rs.getString("name")); grade.setDepartment(rs.getString("department")); grade.setClasses(rs.getInt("classes")); grade.setEnglish(rs.getFloat("english")); grade.setSoft(rs.getFloat("soft")); grade.setOs(rs.getFloat("os")); grade.setJava(rs.getFloat("Java")); grade.setSum(rs.getFloat("sum")); grade.setAverage(rs.getFloat("average")); grade.setDates(rs.getString("dates")); list.add(grade); } }catch(SQLExceptione){ e.printStackTrace(); } conn.queryclose(); returnlist; } /*學(xué)生成績添加方法*/ publicbooleaninsertGrade(Gradegrade){ DBConnectionconn=newDBConnection(); Stringname=grade.getName(); Stringdepartment=grade.getDepartment(); intclasses=grade.getClasses(); floatenglish=grade.getEnglish(); floatsoft=grade.getSoft(); floatos=grade.getOs(); floatjava=grade.getJava(); floatsum=grade.getSum(); floataverage=grade.getAverage(); Stringdates=grade.getDates(); Stringsql="insertintot_grade(name,department,classes,English,soft,os,Java,sum,average,dates)values('"+name+"','"+department+"',"+classes+","+english+","+soft+","+os+","+java+","+sum+","+average+",'"+dates+"')"; intcount=conn.Update(sql); if(count>0){ conn.updateclose(); returntrue; }else{ conn.updateclose(); returnfalse; } } /*按學(xué)號(hào)查詢學(xué)生成績的方法*/ publicGradequerybyId(intid){ Gradeg=newGrade(); Stringsql="select*fromt_gradewhereid="+id+""; DBConnectionconn=newDBConnection(); ResultSetrs=conn.doQuery(sql); try{ if(rs.next()){ g.setId(rs.getInt("id")); g.setName(rs.getString("name")); g.setDepartment(rs.getString("department")); g.setClasses(rs.getInt("classes")); g.setEnglish(rs.getFloat("English")); g.setSoft(rs.getFloat("soft")); g.setOs(rs.getFloat("os")); g.setJava(rs.getFloat("Java")); g.setSum(rs.getFloat("sum")); g.setAverage(rs.getFloat("average")); } }catch(SQLExceptione){ e.printStackTrace(); } conn.queryclose(); returng; } /*學(xué)生成績修改方法*/ publicbooleanAlterGrade(Gradeg){ floatenglish=g.getEnglish(); floatsoft=g.getSoft(); floatos=g.getOs(); floatjava=g.getJava(); floatsum=english+soft+os+java; floataverage=sum/4;

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論