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(String name)thi
2、s。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 getComputer()return com
3、puter;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 = null;Stateme
4、nt 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 (choice)/
5、 添加学生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。getInteger(
6、);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。
7、println(”数学:”);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=” +
8、java + ,computer=” + 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(请输入查找的学生学号:”
9、);cid = Keyboard.getString();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.getS
10、tring(”java”) + t+ rs.getString(”computer) + 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。getIn
11、t(computer”);System.out.println(rs.getString(”sno) + 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()Sy
12、stem.out。println(rs。getInt(1) + t + rs.getInt(2) + t”+ rs.getInt(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)
13、 + ”t”+ rs。getInt(3) + ”t” + rs.getInt(4));/ 输出最低分System。out.println(n各科最低分nn数学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();