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

📄 query.java

📁 学生信息管理
💻 JAVA
字号:
package zhuang;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.sql.*;
public class query extends JFrame implements ActionListener {
	JButton but=new JButton("查询");
	JButton ret=new JButton("返回");
	TextField text;
	String sname;
	Object da[][]=new Object[30][9];
	String ti[]={"编号","学号","姓名","性别","出生年月","院系名称","英语","数学","JAVA"};
	Connection conn;
    Statement stat;
    ResultSet rs;
	public query()throws Exception{
	 	super("查询结果");
        JPanel p=new JPanel(); 
        but.addActionListener(this);
        ret.addActionListener(this);
        this.setVisible(true);
        //this.setSize(400,400);
        JTable table;
        JLabel a=new JLabel("学生信息:"); 
        JLabel b=new JLabel("请输入姓名:"); 
        TextField text=new TextField();
   	    table=new JTable(da,ti);
		JScrollPane pane=new JScrollPane(table);
        p.add(b);
        p.add(text);
        p.add(but);
        p.add(ret);
        this.add(p,"South");
        this.add("Center",pane);
        this.add(a,"North");
        this.setLocation(200,200);
        this.pack();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        this.connection();
	 }	
	  public void connection()
      {
       try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             String url="jdbc:odbc:students";
             conn=DriverManager.getConnection(url);
              stat = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
           } catch (Exception ex){ }
      } 	    
     public void actionPerformed(ActionEvent e) 
     { if(e.getSource()==but)  Show(); 	
       if(e.getSource()==ret) this.setVisible(false);//System.exit(1)
     }
     public void Show(){
      	try{  sname=new String(text.getText());
               String mn=sname;
         	  for(int x=0;x<da.length;x++){
                da[x][0]=null;
                da[x][1]=null;
                da[x][2]=null;
                da[x][3]=null;
                da[x][4]=null;
                da[x][5]=null;
                da[x][6]=null;
                da[x][7]=null;
                da[x][8]=null;
                
              }
            int i=0;
            rs=stat.executeQuery("select * from students where name='"+mn+"'");
            while(rs.next()){
            da[i][0]=rs.getString(1);
            da[i][1]=rs.getString(2);
            da[i][2]=rs.getString(3);
            da[i][3]=rs.getString(4);
            da[i][4]=rs.getString(5);
            da[i][5]=rs.getString(6);
            da[i][6]=rs.getInt(7);
            da[i][7]=rs.getInt(8);
            da[i][8]=rs.getInt(9);
          
            i=i+1;
            }
            this.repaint();
            } catch (SQLException ex) {  }
      }
      public static void main(String args[]) throws Exception{
      	query q=new query();
      }
}

⌨️ 快捷键说明

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