Java综合性试验-信息133-1232-张兴.docx
《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
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 综合性 试验 信息 133 1232
链接地址:https://www.31ppt.com/p-7179799.html