《Java综合性试验-信息133-1232-张兴.docx》由会员分享,可在线阅读,更多相关《Java综合性试验-信息133-1232-张兴.docx(43页珍藏版)》请在三一办公上搜索。
1、成果Java程序设计综合性试验学生成果管理系统学号201212030332姓名张兴班级信息133班试验步1 .数据库、数据表(或数据文件)设计1)学生表信息设计CREATETAB1.Estudentinfo(snoint(20)NOTNU1.1.,sname-varchar(20)NOTNl1.1.,sageint(10)defaultNU1.1.,ssexVtirchur(4)NOTNU1.1.,saddressvarchar(40)NOTNU1.1.,sclass-varchar(20)NOTNU1.1.,PRlMARYKEYCsno),KEYsno(sno)运用uINSERTINTOst
2、udentinfo-VA1.UESCsno,snamc,sage,ssex,saddress,sclass):”语句将学生信息插入生成学生表:;password=prop.gccPropcrty(*passwordM);)六*打开数据库连接tthrow$ClaSSNO(FOUlKlENCePIiOn/,动类找不到拿lhrowsSQ1.Exccplion数据库连接出现问题*throwsNamingEXCCPtiQn/publicvoidgetConn()IhrOWSClaSSNoIFOUndEXCep;Contextcon=newlnitialConccxn():)京执行增、州、改刈语句。*Pa
3、ramSql各种增、删、改语句。“rcturn受影响的行数.publicintUpdale(Stringsql)(inirsl=-I;try(gcConn();s(a(=conn.createStaiene!H();rsl=Stat.CxeculeUpdatc(Sql):)catch(ClassNotFoundExccptionc)(c.prin(S(ackTracc();Icatch(SQ1.Exceione)e.priniStackTrace();)catch(NamingExccptionc)(c.princS(3ckTracc();)finallyIClOSCO:Jreturnrst;
4、)奉* 执行各种查询辆句.京用意:运用完毕后,要单独关闭数据摩资源* ParamSql查询语句* rcturn结果,/publicResuhSeiquerytS(ringsql)(try(gctConn():scat=conn.crcatcStatcmcn();r$=stat.execu(eQuery(sql):)catch(CIaSSN(F0undExccplione)(c.printStackTrace();Icatch(SQI.Exceptionc)e.ri11S(ackTrace();)catch(NaniingExceptione)e.printStackTracc();)reen(
5、);rs=stat.execuieQuery(sql);wh!)e(rs.nex(O)(tryIObjectobj=cls.ncwlnstancc();FieldI!fields=ClsgeiDeciaivdFieIdsO;for(Fieldfield:fields)(Uy(Methodmethodcls.ge(DeclaredMethod(,sefield.geNane().subs(ring(0.1).toU)erCase()+fiekl.ge(Nane,subs(ring(1.field.gelType():methcxi.invokc(obj.ConvcrtUtils.convc11(
6、rs.gctSring(fkld.gc(Namc(),ficld.gcT,peO);Ca【ch(SecurityExceptione)(ITODOAuto-gcne11lcdcatchblockc.printStack,racc():cacch(IllcgalArgumcnlExccptionc)UTODOuto-genera(edcatchblocke.p11nlStackTracc();catch(NoSuchMeth(xiExccptionc)UTODOAuto-gcncratcdcatchblocke.xinStackTrace();catch(InvocationTargelExcc
7、ptione“TODOAuto-gcncratcdcatchblockc.printStackTracc();list.add(obj);)catchinstanliationExccp(ionc)(e.rinStackTraceO:)catch11java.sql.ResuhSei;on:ticy.StuBcan;publicclassStuDaoextendsDbDao显示全部学生信息publicString(showStu()throwsException(Stringa11=newStringge(Rows016J:intrw=0:Stringsq!=sclxtfromStudcntl
8、nlb*;RcsuhSclrs-supcr.qucry(sql);IryIwhi)e(rs.nexlw)(1J=rs.getSlring(2);aDwJ(2=rs.gctJnt(3)+*w;a11w3=rs.getString(4);aIrow4)=rs.geS(ring(5);anw)(5)=rs.gelSlring(6);保循环一次gw加1.并旦连到的记录添加到数组中row*;catch(SQ1.Excepione)ODOAuto-gcncratcdcatchb!kc.princScackTracc();)finally(super.closc():)returna;)添加学生信息publ
9、icintaddStu(intsno.Stringsnamc.intsagc.Stringsscx.Stringsaddrcss.Stringsclass)(Siringsqlwinserti11oStudentInfovalues(,M+sniH,V,+sname+*VM+sage+M+ssex+M,M+saddrcss+,/,+sclass+Mr)M;inti=supcr.update(sql):returni;J/删除学生信刖publicintdclctcStu(intsnol)(Stringsql=dclccfromStudcntinfbwheresno-,wsnol+”:inii=s
10、uper.uxlatesql);returni:)修改学生信息publicinichange(StingsnameJ11sage.S(ringssex.S(ringSaddN$,SIringsc!ass.i11sid)inii=0:Stringsql=updatcstudcntlnosetsnamc=,M+snamc+sagc=*+sage+K,.sscx=,*sscx+,saddrcss=saddrcss+*sclass=nsclass,whereSnO=+sid+二i=su)cr.upda(e(sql);returni:)显示学生成果publicSiringshowScore()throw
11、sExceptionSiringa)11=newSw(3J=rs.getSlring(4):arow(4j=rs.gctString(5):amw5=rs.gccString(6);aIrow116)=rs.ge(String(7);aInw)7=rs.gelinU8)+mm;)returna;)publicSiring(showSlu3(StringXy)throwsException(Stringa(=ncwStringgciRows()J6:introw=0;Stringsql=selectfromSiudeiiUnfbwheresaddress=,M+xy+w,M;RcsuhSelrs
12、=super.query(sql);Irylwhile(rs.xi()/Sys(em.ou(.println(Mrs中彳j数据”);将荏到的记录放到二堆数俎中a|nwJ(OJ=rs.gctlnt(l)+MH;arowl-rs.gc(String(2);amw2j=rsgelm+Ta(rowJ3)=rs.getSlring(4);aIrow(4=rs.gctString(5):arow5=rs.gccString(6);常循环一次MW加1,并且一到的记录添加到数怨中row+:)IcatchISQ1.Exccpiionc)HTODOuio-genera(edcatchblockCpriniSlac
13、kTraceO:Jtinally(supcr.closc();)rew(O)=rs.gellnt(1)mm;aIrow1=rs.gctString(2):arow112=rs.gCHnt(3)+”;aIrow3=rs.ge(String(4);a(row(4j=rs.getSlring(5):a11w(5j=rs.gctSt11ng(6):a11w61=rs.gcString(7);arow1171=rs.ge(I11(8)+,;修循环一次row加1.并且直到的记录添加到数姐中row+:catch(SQ1.EXCCPione)ODoAuto-gcncratcdcatchblockc.princ
14、ScackTracc();)finally(super.closc();)Systcm.ou.prin!n(row);returna;)获得studentinfo表的记录条数publicintgctRows()throwsException!introw=0;Siringsql=selectcount(*)fromsilcnllnfo:RcsuItSctrs=super.qucry(sql):whilc(rs.ncxt()row=rs.gedn(l);)/Systcm.out.println(row);supcr.closc();returnrow:J获得studentinfo表的记录条数pu
15、blicintgclRowsl()throwsExccpiionJintrow=0;Siringsql=selxtcunt(*)fromctnrscinf*:RcsuItSctrs=super.query(sql):whilc(rs.ncxt()w=rs.gedn(l):)/Systcm.out.println(rDw);super.closc();rereturnsid:IpublicvoidSelSid(inisid)lhis.sid=sid:IpublicintgcSno()returnsno;IpublicvoidSetSnO(intsno)(Chissno=sno;IpublicSt
16、ringgelSnaned)returnsname;IpublicvoidSelSIIame(Slringsnane)(his.sname=sname:Ipublicin(getSagc()(returnsage;IpublicvoidsetSagclintsage)(his.sagc=sage;IpublicStringgelSscx()returnssex;IpublicvoidSetSseX(SIringssex)lhis.sscx=Ssex:publicStringgetSaddrcssOreturnSaddrepublicvoidsetSaddrcss(StringSaddrCSS)
17、(his.saddrcss=saddrcss;IpublicStringgclSclass()returnsclass:IpublicvoidSelSdaSS(SIringsclass)(lhis.sclass=sclass;IpublicStringgctCnamc()(returncname;IpublicvoidsetCnamdStringcnamc)IhiSanc-cnamc;IpublicinigelCscorc()returncscore;IpublicvoidSeICSCoN(iinCSCore)(lhis.csjre=cscrc;II6 .增加功能的实现代码产AddlnfoJa
18、va*Createdon_DATE_TIME_WpackageCom.view:importjava.awt.TextField;imx11javax,swing.JOpiionPane;importcm.dao.StuDao:tauthor_USER_publicclassAddlnfoextendsjavax.swingJFramc户CreatesnewtbrnAddInfo*/publicAMnfoOInilComponentsO;this.sctr11tlc(4入窗口):1*Thisn阳hodiscalledfxnwithintheconstructorto*initializethe
19、form. WARNING:DoNO,modifythiscode.Thecontentofthismethodis alwaysregeneratedbytheFormFuiitor. f/GEN-BEGIN:inIlConiponents/privatevoidinitComponcnts()jDialogl=newjavax.swingJDialogO;j1.abel1=newjavax.swingJ1.abcK):JIcxtFicldl=newjavax.swingJTcxtFicld():j4ibc!2二newjavax.swingJI.abcl();jTexField2=newja
20、vax.swingJTextFieldO;jlex(Ficld3=newjavax.swingJTextFieIdO:j,extbicld4=newjavax.swingJTcxtFicIdO;JlcxtFicldS-newjavax.swingJTextFicIdO;j1.abel3=newjavax.swingJ1.abel();j1.abel4=newjavax.swingJ1.abe)():j1.abc!5=newjavax.swingJ1.abcl():jButtonl=newjavax.swingJBuon();jBuon2=newjavax.swingJBuuon();j1.ab
21、el6=newjavax.swingJ1.abc)():jlextEic!d6=newjavax.swingJTcxtFicld():javax.swing.Groupl4iyoutjDialogI1.ayom=newjavax.swing.Group1.ayou(jDialog1.ge(CoineniPaneO);jDialog1.gelContenlPanc().se1.ayout(jDialog!1.ayout):jDialogl1.ayout.sciHorzontalGroup(jDialogl1.ayout.createParallclGroup(javax.swing.Group1
22、.ayout.Alignmcnt1.EADING).addGap(0,400ShoirMzXX-VA1.UE);jDialog11.ayou1.selVerticalGroup(jDialogI1.ayul.crealePa11lklGroup(javax.swing.Groupl-ayout.Alignncnt.1.EADING).addGap(0.300.Short.MAX.VA1.UE);se(DefauhCloseOpenition(javax,swing.WinlowCons(ants.EXiT_ON_C1.OSE);j1.abel1.setFoH(newjaaaw1.Fon(微软德
23、黑.0.18;j1.abel1.setcxt(,u59d3,.u54()d):jIwbcl2.scFom(ncwjaaawi.Fom(“微软雅圾二0,18;j1.abel2.se(lx(,u5e74u9ra4,);j1.abel3.SCIFOtn(newjaaawtFom(微软轴黑,0.18):j1.abcl3.sctTcxt(,u6()27u522b):jl二IhCI4.sclFom(ncwjaaawl.Fon(微软雅黑二0,18;j1.abel4.se(Tex(u73edu7ea7w);j1.abMS.sclFonUncwjuau,Fom(微软雅黑二0.18;j1.abcl5.sdTcxt
24、(u5b66u9662,);jButonl.sc(Tcx(Mu786c5b9a,);jBuon1.addMoUSe1.iSienertnewjava.awi.evem.MouseAdaper()publicvoidrnouseClickedjava.awi.event.MouseEventevt)(jButtonIMouscCiickcd(CVt);)J):jBullon2.sc11x心uS3d6R6d88):jButton2.addMousc1.istcner(ncwjava.awt.cvcnt.MouscAdapcr()(publicvoidmuscClickcdjava.awt.cvcn
25、t.MouscEvcntCVl)(jBton2MouseClicked(evt););j1.bcl6JiClFOm(ncwjaaaw.Fom(徵状雅累二O,18;j1.abel6.$eiTeW”u5b66R53fn:javax.swing.Group1.ayulIayoul=newjavax.swing.Group1.ayiMil(gctContcntPanc();gc,out.se(Horizonta!Group(layout.crenteParallelGroup(javax.swing.Gr)up1.iout.AHgnnwnt.1.EADiNG).addGroupup(javax.swi
26、ng.Gfoup1.ayoui.Alignment.1.E?DING).adIGruplayout.crcatcScqucntialGroup().addConponen(j1.abel2).addGap(18.18.8).aldComponeni(jTcxtField2.javax.swing.Group1.ayout.DEFAU1.T.SIZE.122.Sho11.MAX-VA-UE),addGroXlayout.crcatcScqucntialGroup().idComponcnt(j1.abel3).addGap(18.18.18).addComponcH(jTex(Field3.ja
27、vax.swing.Groupl.ayout.DEFAUI.T_SIZE.22.Short.MAX-VA1.UE).a(kiGroupIayoutxrealcSequcntialGnMip.addPrccrrcdGap(javiix.swing.1.ayou(Stylepone11Pkcement.RE1.ATED).addCmponcnl(j1.abcl4).addGap(18,18,18).addCmp)ncnl(jTcxtFicld4.javax.swtng.Group1.ayoutDEFAU1.TjSlZE,122,Shor(AIAX-VA1.UE).addGrouplayut.crc
28、atcScqucntialGrop().aldPefe11dGap(javax.swing.1.ayoutStylepwcntPlaccmcnt.RE1.AED).aupup(jBuon2).addGap25.25,25).addGroupup(javax.swing.Grup1.ayout.Align11cnl.1.EADING).addComponcnt(j1.abell.javax.swing.Group1.ayom.PREFERRED_SlZE,50.javax.suing.Groupl.ayout.PREFERRED_SIZE).addComponent(jlbe16).addGa(
29、5.5.5).iiddGrxup(IayautxrcatcParaIlclGroup(javax.swing.Gro.addContaincrCiap(65.Sbort.MAX.VA1.UE);layout.sc(rticalGroup(layout,createParallelGtup(javax.swing.G!up1.ayol.Alignnwnt.1.EADING).addGroupup(javax.swing.Grup(javax.swing.GroupI.ayout.Alignmcn.BASEI.iNE)二UMCOmPonenNj1.abell.javax.swing.Groupl.
30、ayout.PREFERRED-SIZE,javax.swing.Group1.ayout.PREEERRED_SlZli).addCmponcnt(jlx(Field1.javax.swing.Group1.ayout.PREHiRRED_SlZE.26,javax.swing.Grup1.ayout.PREFERRED-SIZE).addPrcfccdGap(javax.swing.IUiyoutStyIcPoneiHPIacement.RE1.ATED).addG11)up(layout.creatcParallclGroup(javax.swing.Group1.ayout.Alignment.BASE1.INE).aklCo11