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

📄 tyj.java

📁 学生信息管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package test;

import java.sql.*; 
import java.awt.*; 
import javax.swing.*; 
import java.awt.event.*; 
import javax.swing.border.*; 
import javax.swing.JOptionPane; 
class Add extends Panel implements ActionListener{ 
  Connection con; 
  Statement sql; 
  Button b1,b2; 
  TextField tf1,tf2,tf3,tf4,tf5,tf6; 
  Box baseBox,bv1,bv2; 
  Add(){ 
  	try{ 
  		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
  		} 
  	catch(ClassNotFoundException e){} 
    try{ 
    	con=DriverManager.getConnection("jdbc:odbc:data","",""); 
    	sql=con.createStatement(); 
    } 
    catch(SQLException ee){} 
  	setLayout(new BorderLayout()); 
  	Panel p1=new Panel(); 
  	Panel p2=new Panel(); 
  	tf1=new TextField(16); 
  	tf2=new TextField(16); 
  	tf3=new TextField(16); 
  	tf4=new TextField(16); 
  	tf5=new TextField(16); 
  	tf6=new TextField(16); 
  	b1=new Button("录入"); 
  	b1.setBackground(Color.green); 
  	b2=new Button("重置"); 
  	b2.setBackground(Color.green); 
  	b1.addActionListener(this); 
  	b2.addActionListener(this); 
  	p1.add(b1); 
  	p1.add(b2); 
  	bv1=Box.createVerticalBox(); 
  	bv1.add(new Label("学号")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv1.add(new Label("姓名")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv1.add(new Label("性别")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv1.add(new Label("专业")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv1.add(new Label("年级")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv1.add(new Label("出生")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv2=Box.createVerticalBox(); 
  	bv2.add(tf1); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	bv2.add(tf2); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	bv2.add(tf3); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	bv2.add(tf4); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	bv2.add(tf5); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	bv2.add(tf6); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	baseBox=Box.createHorizontalBox(); 
  	baseBox.add(bv1); 
  	baseBox.add(Box.createHorizontalStrut(10)); 
  	baseBox.add(bv2); 
  	p2.add(baseBox); 
  	add(p1,"South"); 
  	add(p2,"Center"); 
  	setSize(350,300); 
  	setBackground(Color.pink); 
  } 
  public void actionPerformed(ActionEvent e){ 
  	if(e.getSource()==b1){ 
  		try{ insert();} 
  		catch(SQLException ee){} 
  		JOptionPane.showMessageDialog(this,"数据已入库!","提示对话框",JOptionPane.INFORMATION_MESSAGE); 
  	} 
  	else if(e.getSource()==b2){ 
  	    tf1.setText(" "); 
  	    tf2.setText(" "); 
  	    tf3.setText(" "); 
  	    tf4.setText(" "); 
  	    tf5.setText(" "); 
  	    tf6.setText(" "); 
  	} 
  } 
  public void insert() throws SQLException{ 
  	String s1="'"+tf1.getText().trim()+"'"; 
  	String s2="'"+tf2.getText().trim()+"'"; 
  	String s3="'"+tf3.getText().trim()+"'"; 
  	String s4="'"+tf4.getText().trim()+"'"; 
  	String s5="'"+tf5.getText().trim()+"'"; 
  	String s6="'"+tf6.getText().trim()+"'"; 
  	String temp="INSERT INTO jesse VALUES ("+s1+","+s2+","+s3+","+s4+","+s5+","+s6+")"; 
    con=DriverManager.getConnection("jdbc:odbc:data","",""); 
    sql.executeQuery(temp); 
  	con.close(); 
  }	 
} 
class Query extends Panel implements ActionListener{ 
  Connection con; 
  Statement sql; 
  TextField t1,t2,t3,t4,t5,t6; 
  Button b; 
  Box baseBox,bv1,bv2; 
  int flag=0; 
  Query(){ 
  	try{ 
  		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
  		} 
  	catch(ClassNotFoundException e){} 
    try{ 
    	con=DriverManager.getConnection("jdbc:odbc:data","",""); 
    	sql=con.createStatement(); 
    } 
    catch(SQLException ee){} 
    setLayout(new BorderLayout()); 
    b=new Button("查询"); 
    b.setBackground(Color.orange); 
    b.addActionListener(this); 
    t1=new TextField(8); 
    t2=new TextField(16); 
    t3=new TextField(16); 
    t4=new TextField(16); 
    t5=new TextField(16); 
    t6=new TextField(16); 
    t2.setEditable(false); 
    t3.setEditable(false); 
    t4.setEditable(false); 
    t5.setEditable(false); 
    t6.setEditable(false); 
    Panel p1=new Panel(),p2=new Panel(); 
    p1.add(new Label("输入要查询的学号")); 
    p1.add(t1); 
    p1.add(b); 
    bv1=Box.createVerticalBox(); 
  	bv1.add(new Label("姓名")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv1.add(new Label("性别")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv1.add(new Label("专业")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv1.add(new Label("年级")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv1.add(new Label("出生")); 
  	bv1.add(Box.createVerticalStrut(8)); 
  	bv2=Box.createVerticalBox(); 
  	bv2.add(t2); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	bv2.add(t3); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	bv2.add(t4); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	bv2.add(t5); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	bv2.add(t6); 
  	bv2.add(Box.createVerticalStrut(8)); 
  	baseBox=Box.createHorizontalBox(); 
  	baseBox.add(bv1); 
  	baseBox.add(Box.createHorizontalStrut(10)); 
  	baseBox.add(bv2); 
  	p2.add(baseBox); 
  	add(p1,"North"); 
  	add(p2,"Center"); 
  	setSize(300,250); 
  	setBackground(Color.red); 
  } 
  public void actionPerformed(ActionEvent e){ 
  	flag=0; 
  	try{query();} 
  	catch(SQLException ee){} 
  } 
  public void query() throws SQLException{ 
  	String num,name,sex,subject,grade,born; 
  	con=DriverManager.getConnection("jdbc:odbc:data","",""); 
  	ResultSet rs=sql.executeQuery("SELECT * FROM jesse "); 
  	while(rs.next()){ 
  		num=rs.getString("学号"); 
  		name=rs.getString("姓名"); 
  		sex=rs.getString("性别"); 
  		subject=rs.getString("专业"); 
  		grade=rs.getString("年级"); 
  		born=rs.getString("出生"); 
  		if(num.equals(t1.getText().trim())){ 
  			t2.setText(name); 
  			t3.setText(sex); 
  			t4.setText(subject); 
  			t5.setText(grade); 
  			t6.setText(born); 
  			flag=1; 
  			break; 
  		} 
  	} 
  	con.close(); 
  	if(flag==0){t1.setText("没有该学生");} 
  } 
} 
class Update extends Panel implements ActionListener{ 
  Connection con; 
  Statement sql; 
  Button b1,b2,b3; 
  Box baseBox,bv1,bv2; 
  TextField t1,t2,t3,t4,t5,t6; 
  Update(){ 
  	try{ 
  		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
  		} 
  	catch(ClassNotFoundException e){} 
    try{ 
    	con=DriverManager.getConnection("jdbc:odbc:data","",""); 
    	sql=con.createStatement(); 
    } 
    catch(SQLException ee){} 
    setLayout(new BorderLayout()); 
    b1=new Button("开始修改"); 
    b1.setBackground(Color.green); 
    b2=new Button("录入修改"); 
    b2.setBackground(Color.yellow); 
    b3=new Button("重置"); 
    b3.setBackground(Color.yellow); 
    b1.addActionListener(this); 
    b2.addActionListener(this); 
    b3.addActionListener(this); 
    t1=new TextField(8); 
    t2=new TextField(16); 
    t3=new TextField(16); 
    t4=new TextField(16); 
    t5=new TextField(16); 
    t6=new TextField(16); 
    Panel p1=new Panel(),p2=new Panel(),p3=new Panel(); 
    p1.add(new Label("输入要修改信息的学号")); 
    p1.add(t1); 
    p1.add(b1); 
    bv1=Box.createVerticalBox(); 
    bv1.add(new Label("(新)姓名")); 
    bv1.add(Box.createVerticalStrut(8)); 
    bv1.add(new Label("(新)性别")); 
    bv1.add(Box.createVerticalStrut(8)); 
    bv1.add(new Label("(新)专业")); 
    bv1.add(Box.createVerticalStrut(8)); 
    bv1.add(new Label("(新)年级")); 
    bv1.add(Box.createVerticalStrut(8)); 
    bv1.add(new Label("(新)出生")); 
    bv1.add(Box.createVerticalStrut(8)); 
    bv2=Box.createVerticalBox(); 
    bv2.add(t2); 
    bv2.add(Box.createVerticalStrut(8)); 
    bv2.add(t3); 
    bv2.add(Box.createVerticalStrut(8)); 
    bv2.add(t4); 
    bv2.add(Box.createVerticalStrut(8)); 
    bv2.add(t5); 
    bv2.add(Box.createVerticalStrut(8)); 
    bv2.add(t6); 
    bv2.add(Box.createVerticalStrut(8)); 
    baseBox=Box.createHorizontalBox(); 
    baseBox.add(bv1); 
    baseBox.add(Box.createHorizontalStrut(10)); 
    baseBox.add(bv2); 
    p2.add(baseBox); 
    p3.add(b2); 

⌨️ 快捷键说明

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