⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yht.java

📁 用JAVA编写的简单学生成绩管理系统
💻 JAVA
字号:
import java.sql.*;
import java.awt.event.*;
import java.awt.*;
public class Yht extends Frame implements ActionListener{
	Label prompt,l1,l2,l3,l4,l5;
	TextField t1,t2,t3,t4,t5;
	float s1,s2,s3;
	int i=5,count1;
	float ss;
	Choice sno;
	Button button1,button2,button3,button4,button5,button6;
	TextArea result;
	public Yht(){
		setTitle("Welcome to YHTDBquery");
		setLayout(new FlowLayout());
		addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){
				System.exit(0);
			}
		});
		prompt=new Label("sno");
		l1=new Label("INPUT rgrade");
		t1=new TextField();
		l2=new Label("pgrade");
		t2=new TextField();
		l3=new Label("cgrade");
		t3=new TextField();
		l4=new Label("GRADE between");
		t4=new TextField();
		l5=new Label("and");
		t5=new TextField();
		sno=new Choice();
		button1=new Button("update");
		button2=new Button("cancel");
		button3=new Button("5first");
		button4=new Button("fail");
		button5=new Button("proportion");
		button6=new Button("select");
		result=new TextArea();
		try{
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			String url="jdbc:odbc:yht";
        	String user="yht";
        	String password="yht";
        	String ls_1="select sno from sgrade ";
        	Connection con=DriverManager.getConnection(url,user,password);
        	Statement stmt=con.createStatement();
        	ResultSet rs=stmt.executeQuery(ls_1);
        	while(rs.next()){
        		sno.add(rs.getString(1));
        	}
        rs.close();
        stmt.close();
        con.close();
		}
    catch(SQLException sqle){}
    catch(Exception e){}
    add(prompt);
    add(sno);
    add(l1);
    add(t1);
    add(l2);
    add(t2);
    add(l3);
    add(t3);
    add(button1);
    add(button2);
    add(l4);
    add(t4);
    add(l5);
    add(t5);
    add(button5);
    add(button3);
    add(button4);
    add(button6);
    add(result,BorderLayout.SOUTH);
    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
    button4.addActionListener(this);
    button5.addActionListener(this);
    button6.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e){
    	if(e.getSource()==button1){
    		try{
    		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			String url="jdbc:odbc:yht";
        	String user="yht";
        	String password="yht";
        	String querysno=sno.getSelectedItem();
        	s1=Float.valueOf(t1.getText()).floatValue();
			s2=Float.valueOf(t2.getText()).floatValue();
			s3=Float.valueOf(t3.getText()).floatValue();
			s3*=0.7;
			ss=s1+s2+s3;
        	String ls_1="select * from sgrade"+" where sno="+querysno;
        	String ls_2="update sgrade"+" set rgrade="+t1.getText()+" where sno="+
        	querysno;
        	String ls_3="update sgrade"+" set pgrade="+t2.getText()+" where sno="+
        	querysno;
        	String ls_4="update sgrade"+" set cgrade="+t3.getText()+" where sno="+
        	querysno;
        	String ls_5="update sgrade"+" set grade="+ss+" where sno="+
        	querysno;
        	Connection con=DriverManager.getConnection(url,user,password);
        	Statement stmt=con.createStatement();
        	ResultSet rs=stmt.executeQuery(ls_1);
        	result.setText(" ");
        	while(rs.next()){
        		String msg=rs.getInt(1)+" | "+rs.getString(2)+"rgrade: "+
        		rs.getInt(3)+" pgrade: "+rs.getInt(4)+" cgrade: "+rs.getInt(5)+" grade: "+
        		rs.getInt(6);
        		result.append(msg);
        	}
        	stmt.executeUpdate(ls_2);
        	stmt.executeUpdate(ls_3);
        	stmt.executeUpdate(ls_4);
        	stmt.executeUpdate(ls_5);
        	while(rs.next()){
        	String msg=rs.getInt(1)+" | "+rs.getString(2)+"rgrade: "+
        		rs.getInt(3)+" pgrade: "+rs.getInt(4)+" cgrade: "+rs.getInt(5)+" grade: "+
        		rs.getInt(6);
        		result.append(msg);
        	}
        rs.close();
        stmt.close();
        con.close();
        }
        catch(SQLException sqle){}
    	catch(Exception exce){}
    	}
    	if(e.getSource()==button2){
    	try{
    			t1.setText("");
    			t2.setText("");
    			t3.setText("");
    			t4.setText("");
    			t5.setText("");
    			}
    	catch(Exception exce){}
    	}
   		if(e.getSource()==button3){
    		try{
    		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			String url="jdbc:odbc:yht";
        	String user="yht";
        	String password="yht";
        	String ls_1="select * from sgrade"+" order by grade DESC";
        	Connection con=DriverManager.getConnection(url,user,password);
        	Statement stmt=con.createStatement();
        	ResultSet rs=stmt.executeQuery(ls_1);
        	result.setText("first 5 student:\n");
        	while(rs.next()){
        		if(i>0){
        		String msg=rs.getInt(1)+" | "+rs.getString(2)+" | "+
        		rs.getInt(3)+" | "+rs.getInt(4)+" | "+rs.getInt(5)+" | "+rs.getInt(6)+'\n';
        		i--;
        		result.append(msg);
        		}
        	}
        rs.close();
        stmt.close();
        con.close();
        }
        catch(SQLException sqle){}
    	catch(Exception exce){}
    	}
    	if(e.getSource()==button4){
    		try{
    		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			String url="jdbc:odbc:yht";
        	String user="yht";
        	String password="yht";
        	String ls_1="select sno,sname,grade from sgrade"+" where grade<60";
        	Connection con=DriverManager.getConnection(url,user,password);
        	Statement stmt=con.createStatement();
        	ResultSet rs=stmt.executeQuery(ls_1);
        	result.setText("fail:\n");
        	while(rs.next()){
        		String msg=rs.getInt(1)+" | "+rs.getString(2)+'\n';
        		result.append(msg);
        	}
        rs.close();
        stmt.close();
        con.close();
        }
        catch(SQLException sqle){}
    	catch(Exception exce){}
    	}
    	if(e.getSource()==button5){
    		try{
    		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			String url="jdbc:odbc:yht";
        	String user="yht";
        	String password="yht";
        	String ls_1="select count(*)  from sgrade"+" where grade between "+
        	t4.getText()+" and "+t5.getText();
        	Connection con=DriverManager.getConnection(url,user,password);
        	Statement stmt=con.createStatement();
        	ResultSet rs=stmt.executeQuery(ls_1);
        	result.setText("proportion:\n");
        	while(rs.next()){
        		String msg=t4.getText()+"--"+t5.getText()+" | "+rs.getString(1);
        		result.append(msg);
        	}
        rs.close();
        stmt.close();
        con.close();
        }
        catch(SQLException sqle){}
    	catch(Exception exce){}
    	}
      	if(e.getSource()==button6){
    		try{
    		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			String url="jdbc:odbc:yht";
        	String user="yht";
        	String password="yht";
        	String ls_1="select * from sgrade"+" order by grade DESC";
        	Connection con=DriverManager.getConnection(url,user,password);
        	Statement stmt=con.createStatement();
        	ResultSet rs=stmt.executeQuery(ls_1);
        	result.setText("all student:\n");
        	while(rs.next()){
        		String msg=rs.getInt(1)+" | "+rs.getString(2)+"rgrade: "+
        		rs.getInt(3)+" pgrade: "+rs.getInt(4)+" cgrade: "+rs.getInt(5)+" grade: "+
        		rs.getInt(6)+'\n';
        		result.append(msg);
        		
        	}
        rs.close();
        stmt.close();
        con.close();
        }
        catch(SQLException sqle){}
    	catch(Exception exce){}
    	}
    }
        public static void main(String args[]){
        	Yht nowFrame=new Yht();
        	nowFrame.resize(600,400);
        	nowFrame.show(); 
        }
       
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -