📄 teamgame.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package sports;import java.awt.*;import java.awt.Checkbox.*;import java.awt.event.* ;import java.sql.*;/** * * 团体成绩统计表 */class TeamGame extends Frame implements ActionListener{ Choice choice; TextArea ta; Button b1,b2; Connection conn,con ; Statement sm,sm1,sm2,sm3,sm4 ; ResultSet rs,rs1,rs2,rs3,rs4 ; //int r1,r2,r3,r4; TeamGame(){ setSize(400,350); setBackground(Color.pink); setLocation(400,250); setResizable(false); setLayout(new FlowLayout()); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { dispose(); }}); ta=new TextArea(12,50); Label l=new Label("请选择您要查询的学院"); b1=new Button("确定"); b2=new Button("返回"); add(l); choice=new Choice(); choice.add("计算机学院"); choice.add("管理学院"); choice.add("交通学院"); choice.add("物流学院"); add(choice); add(b1); add(b2); add(ta); b1.addActionListener(this); b2.addActionListener(this); setVisible(true); } public void actionPerformed(ActionEvent e){ //int n=0; int i=1; String mc=" "; if(e.getSource()==b1){ ta.setText("查询结果是\n"); String ch=choice.getSelectedItem(); try { Class.forName("com.mysql.jdbc.Driver"); } catch (java.lang.ClassNotFoundException ee) { System.out.println("驱动加载失败,属于系统错误,请与管理员联系!"); } try{ conn = DriverManager .getConnection("jdbc:mysql://localhost:3306/sports?user=root&password=root"); sm = conn.createStatement(); } catch (SQLException kk) { System.out.println("数据库连接失败,请查看服务器是否开启!"); } try{ rs1=sm.executeQuery("select SDEPT, SUM(SCORE) from totalgame group by SDEPT ORDER BY SUM(SCORE) DESC"); while(rs1.next()){ if(!ch.equals(rs1.getString(1))){ i=i+1; }else{ break ; } } mc=String.valueOf(i); } catch(SQLException es){} try{ int index = 0; rs=sm.executeQuery("select SUM(SCORE) from totalgame where SDEPT='"+ch+"'"); if(rs.next()) index=1; if(index==1){ ta.append("学院 "+"得分 "+"名次 "); ta.append("\n"+ch+" "+rs.getInt(1)+" "+mc+" "); } else{ ta.append("\n"+"您所要查询的项目成绩统计暂未输入或者此次运动会没有该学院参加"); } } catch(SQLException eee){ eee.printStackTrace(); new ErrorDialog(this,"提示","数据操作失败"); } } else{ dispose(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -