您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 薪酬管理 > JAVA学生信息管理系统源代码
//studentimportjava.sql.*;importjava.util.Scanner;importjava.io.*;publicclassstudent{privateStringid;privateStringname;privateintmath;privateintenglish;privateintjava;privateintcomputer;privatestaticStringinput=;privatestaticintchoice;Stringcid;Statementstmt;ResultSetrs;privatestaticConnectionconn=null;privatestaticStringusername=root;//数据库用户名privatestaticStringpassword=;//密码privatestaticStringserver=localhost:3306;privatestaticStringdbname=test;//数据库名publicstaticvoidmain(String[]args)throwsException{studentstart=newstudent();start.getDataConnect();while(true){start.inputSelect();if(choice==0)break;Strings=\n\n\t\t\t学生信息系统\n\n\t\t1新增\n\t\t2更改\n\t\t3删除\n\t\t4查找\n\t\t5显示\n\t\t0退出\n\n;System.out.print(s);Stringt=(请输入相应的序号:);System.out.print(t);}conn.close();}publicStringgetId(){returnid;}publicvoidsetId(Stringid){this.id=id;}publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicintgetMath(){returnmath;}publicvoidsetMath(intmath){this.math=math;}publicintgetEnglish(){returnenglish;}publicvoidsetEnglish(intenglish){this.english=english;}publicintgetJava(){returnjava;}publicvoidsetJava(intjava){this.java=java;}publicintgetComputer(){returncomputer;}publicvoidsetComputer(intcomputer){this.computer=computer;}publicvoidgetDataConnect(){//TODOAuto-generatedmethodstubtry{//注册JDBC连接驱动Class.forName(org.gjt.mm.mysql.Driver);}catch(Exceptione){System.out.println(e.toString());System.out.println(无法加载数据库驱动);}try{conn=DriverManager.getConnection(jdbc:mysql://+server+/+dbname,username,password);}catch(Exceptione){System.out.println(e.toString());}Strings=\n\n\t\t\t学生信息系统\n\n\t\t1新增\n\t\t2更改\n\t\t3删除\n\t\t4查找\n\t\t5显示\n\t\t0退出\n\n;System.out.print(s);Stringt=(请输入相应的序号:);System.out.print(t);}publicvoidinputSelect(){while(true){try{BufferedReaderbuffer=newBufferedReader(newInputStreamReader(System.in));input=buffer.readLine();choice=Integer.parseInt(input);if(choice0||choice5){thrownewException();}elsebreak;}catch(Exceptione){System.out.println(输入有误,请重新输入!);}}switch(choice){//添加学生case1:aa();try{stmt=conn.createStatement();System.out.println(id);System.out.println(insertintosssvalues('+id+','+name+','+math+','+english+','+java+','+computer+'));stmt.executeUpdate(insertintosssvalues('+id+','+name+','+math+','+english+','+java+','+computer+'));}catch(Exceptione){}System.out.println(\n添加完成。);break;//更改成绩case2:aa();try{stmt=conn.createStatement();stmt.executeUpdate(updatessssetmath='+math+',english='+english+',java='+java+',computer='+computer+'wheresno=+cid+);}catch(Exceptione){}System.out.println(\n修改完成);break;//删除指定学生case3:System.out.println(请输入要改的学生学号:);Scannerreader_cid=newScanner(System.in);Stringcid=reader_cid.next();try{stmt=conn.createStatement();System.out.println(deletefromssswhereid='+cid+');stmt.executeUpdate(deletefromssswhereid='+cid+');}catch(Exceptione){}System.out.println(\n删除完成);break;//显示指定学生case4:System.out.println(请输入查找的学生学号:);Scannerreader_ad=newScanner(System.in);Stringad=reader_ad.next();System.out.println(\n+ad+号学生信息\n\n学号\t姓名\t数学\t英语\tJAVA\t计算机\t);try{stmt=conn.createStatement();System.out.println(select*fromssswhereid='+ad+');rs=stmt.executeQuery(select*fromssswhereid='+ad+');while(rs.next()){System.out.println(rs.getString(1)+\t+rs.getString(2)+\t+rs.getInt(3)+\t+rs.getInt(4)+\t+rs.getInt(5)+\t+rs.getInt(6)+\t);}}catch(Exceptione){}break;case5://输出全部信息System.out.println(\n全部学生信息\n\n学号\t姓名\t数学\t英语\tJAVA\t计算机\t平均成绩);try{stmt=conn.createStatement();rs=stmt.executeQuery(select*fromsssorderbymathdesc);while(rs.next()){inta=rs.getInt(3);intb=rs.getInt(4);intc=rs.getInt(5);intd=rs.getInt(6);System.out.println(rs.getString(1)+\t+rs.getString(2)+\t+a+\t+b+\t+c+\t+d+\t+((a+b+c+d)/4));}}catch(Exceptione){System.out.println(Queryerror!);}break;case0:break;default:System.out.println(感谢您的使用,再见!);}}publicvoidaa(){System.out.print(请输入学生信息\n);System.out.println(请输入学号);Scannerreader_id=newScanner(System.in);id=reader_id.next();System.out.println(请输入姓名);Scannerreader_name=newScanner(System.in);name=reader_id.next();System.out.println(请输入数学成绩);Scannerreader_math=newScanner(System.in);Stringstr_math=reader_math.next();math=Integer.parseInt(str_math);System.out.println(请输入英语成绩);Scannerreader_english=newScanner(System.in);Stringstr_english=reader_english.next();english=Integer.parseInt(str_english);System.out.println(请输入java成绩);Scannerreader_java=newScanner(System.in);Stringstr_java=reader_java.next();java=Integer.parseInt(str_java);System.out.println(请输入计算机成绩);Scannerreader_computer=newScanner(System.in);Stringstr_computer=reader_computer.next();computer=Integer.parseInt(str_computer);}}
本文标题:JAVA学生信息管理系统源代码
链接地址:https://www.777doc.com/doc-4326529 .html