《用java编写的学生成绩管理系统代码(共6页).doc》由会员分享,可在线阅读,更多相关《用java编写的学生成绩管理系统代码(共6页).doc(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上/studentimport java.sql.*;public class Studentprivate String id;private String name;private int math;private int english;private int java;private int computer;public String getId()return id;public void setId(String id)this.id = id;public String getName()return name;public void setName(S
2、tring name)this.name = name;public int getMath()return math;public void setMath(int math)this.math = math;public int getEnglish()return english;public void setEnglish(int english)this.english = english;public int getJava()return java;public void setJava(int java)this.java = java;public int getComput
3、er()return computer;public void setComputer(int computer)puter = computer;public static void main(String args) throws ExceptionString id;String cid;String name;int math;int english;int java;int computer;String DBDriver = sun.jdbc.odbc.JdbcOdbcDriver;String conStr = jdbc:odbc:student;Connection con =
4、 null;Statement stmt = null;ResultSet rs = null;Class.forName(DBDriver);con = DriverManager.getConnection(conStr, student, 123);stmt = con.createStatement();String s = nnttt学 生 成 绩nntt 1 新 增ntt 2 更 改ntt 3 删 除ntt 4 查 找ntt 5 显 示ntt 0 退 出nn;System.out.print(s);int choice = Keyboard.getInteger();switch
5、(choice)/ 添加学生case 1:System.out.print(请输入学生信息n);System.out.print(学号:);id = Keyboard.getString();System.out.print(姓名:);name = Keyboard.getString();System.out.print(数学:);math = Keyboard.getInteger();System.out.print(英语:);english = Keyboard.getInteger();System.out.print(JAVA:);java = Keyboard.getIntege
6、r();System.out.print(计算机:);computer = Keyboard.getInteger();stmt.executeUpdate(insert into lxh1 values( + id + ,+ name + , + math + , + english + , + java+ , + computer + );System.out.println(n添加完成。);break;/ 更改成绩case 2:System.out.println(请输入要改的学生学号:);cid = Keyboard.getString();System.out.println(数学:
7、);math = Keyboard.getInteger();System.out.println(英语:);english = Keyboard.getInteger();System.out.println(JAVA:);java = Keyboard.getInteger();System.out.println(计算机:);computer = Keyboard.getInteger();stmt.executeUpdate(update lxh1 set math= + math + ,english=+ english + ,java= + java + ,computer= +
8、computer+ where sno= + cid + );System.out.println(n修改完成);break;/ 删除指定学生case 3:System.out.println(请输入要改的学生学号:);cid = Keyboard.getString();stmt.executeUpdate(delete from lxh1 where sno= + cid + );System.out.println(n删除完成);break;/ 显示指定学生case 4:System.out.println(请输入查找的学生学号:);cid = Keyboard.getString();
9、System.out.println(n + cid+ 号学生信息nn学号t姓名t数学t英语tJAVAt计算机t);rs = stmt.executeQuery(select * from lxh1 where sno= + cid+ );while (rs.next()System.out.println(rs.getInt(sno) + t+ rs.getString(sname) + t + rs.getString(math)+ t + rs.getString(english) + t+ rs.getString(java) + t+ rs.getString(computer) +
10、 t);break;case 5:/ 输出全部信息System.out.println(n全部学生信息nn学号t姓名t数学t英语tJAVAt计算机t平均成绩);rs = stmt.executeQuery(select * from lxh1 order by math desc);while (rs.next()int a = rs.getInt(math);int b = rs.getInt(english);int c = rs.getInt(java);int d = rs.getInt(computer);System.out.println(rs.getString(sno) +
11、t+ rs.getString(sname) + t + a + t + b + t+ c + t + d + t + (a + b + c + d) / 4);/ 输出平均分System.out.println(n各科平均分nn数学t英语tJAVAt计算机t);rs = stmt.executeQuery(select avg(math),avg(english),avg(java),avg(computer) from lxh1);while (rs.next()System.out.println(rs.getInt(1) + t + rs.getInt(2) + t+ rs.getIn
12、t(3) + t + rs.getInt(4);/ 输出最高分System.out.println(n各科最高分nn数学t英语tJAVAt计算机t);rs = stmt.executeQuery(select max(math),max(english),max(java),max(computer) from lxh1);while (rs.next()System.out.println(rs.getInt(1) + t + rs.getInt(2) + t+ rs.getInt(3) + t + rs.getInt(4);/ 输出最低分System.out.println(n各科最低分n
13、n数学t英语tJAVAt计算机t);rs = stmt.executeQuery(select min(math),min(english),min(java),min(computer) from lxh1);while (rs.next()System.out.println(rs.getInt(1) + t + rs.getInt(2) + t+ rs.getInt(3) + t + rs.getInt(4);break;case 0:break;default:System.out.println(感谢您的使用,再见!);stmt.close();con.close();专心-专注-专业