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

📄 select.java

📁 人员管理系统
💻 JAVA
字号:
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;

public class select extends JFrame{
    
    private JLabel name,no,sex,address,polity,health,compact,wno,wname;
	private JLabel name1,no1,sex1,address1,polity1,health1,compact1,wno1,wname1;
	private JLabel work1,work2,work3;
	private JButton select,add,delete,exist;
	private JTextField namet,not,sext,addresst,polityt,healtht,compactt,work1t,work2t,work3t,wnot,wnamet;
	
    static final String JDBC_DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";
    static final String DATABASE_URL = "jdbc:odbc:RSGLDSN";
   
    private Connection connection;
    private Statement statement;
    String sqlString ;
   
	public select(){
		super("企业人事管理");
		initialize();
		Container container=getContentPane();
		 
		no=new JLabel("  工   号:    ");
	    no1=new JLabel("99999999            ");
		name=new JLabel("姓   名:   ");
		name1=new JLabel("******************");
		sex=new JLabel("性   别:  ");
		sex1=new JLabel("男/女                ");
		address=new JLabel("地   址:  " );
		address1=new JLabel("***...***   (50)    ");
		polity=new JLabel("政治面貌:");
		polity1=new JLabel("群众/团员/党员 ");
		health=new JLabel("生理状况:");
		
		health1=new JLabel("优/良/中/差     ");
		compact=new JLabel("合同:  ");
		compact1=new JLabel("99年                ");
		wno=new JLabel("部门号: ");
		wno1=new JLabel("99999999           ");
		wname=new JLabel(" 部门名: ");
		wname1=new JLabel("***...****     (25)    ");
		work1=new JLabel("加班次: ");
		work2=new JLabel("出差次: ");
		work3=new JLabel("迟到次: ");

		not=new JTextField(20);
		namet=new JTextField(20);
		sext=new JTextField(20);
		addresst=new JTextField(20);
		polityt=new JTextField(20);
		healtht=new JTextField(20);
		compactt=new JTextField(20);
		wnot=new JTextField(20);
		wnamet=new JTextField(20);
		work1t=new JTextField(6);
		work2t=new JTextField(6);
		work3t=new JTextField(6);

		select=new JButton("查找");
		add=new JButton("添加");
		delete=new JButton("删除");
		exist=new JButton("退出");
		
		JPanel j1=new JPanel();
		JPanel j2=new JPanel();
		
								
		container.setLayout(new BorderLayout());
		j1.setLayout(new FlowLayout());
		j2.setLayout(new FlowLayout());
		
		container.add(j1,BorderLayout.CENTER);
		container.add(j2,BorderLayout.SOUTH);
		
		j1.add(no);
		j1.add(not);
		j1.add(no1);
		j1.add(name);
		j1.add(namet);
		j1.add(name1);
		j1.add(sex);
		j1.add(sext);
		j1.add(sex1);
		j1.add(address);
		j1.add(addresst);
		j1.add(address1);
		j1.add(polity);
		j1.add(polityt);
		j1.add(polity1);
		j1.add(health);
		j1.add(healtht);
		j1.add(health1);
		j1.add(compact);
		j1.add(compactt);
		j1.add(compact1);
		j1.add(wno);
		j1.add(wnot);
		j1.add(wno1);
		j1.add(wname);
		j1.add(wnamet);
		j1.add(wname1);
		j1.add(work1);
		j1.add(work1t);
		j1.add(work2);
		j1.add(work2t);
		j1.add(work3);
		j1.add(work3t);


		j2.add(select);
	
		select.addActionListener(

            new ActionListener() {
                 public void actionPerformed( ActionEvent event )
            		{
                			DisplayRecord();
            		}
           } 
        );
        
        addWindowListener(

         // anonymous inner class to handle windowClosing event
         new WindowAdapter() {

            // add current record in GUI to file, then close file
            public void windowClosing( WindowEvent event )
            {
               
               terminate();//close connectin
            }

         } // end anonymous inner class

      ); // end call to addWindowListener
        
        setSize(420,400);
		setVisible(true);
       } 
        public  void initialize()
        {
       		try {
                 	Class.forName( JDBC_DRIVER );
                  connection = DriverManager.getConnection( DATABASE_URL,"sa",null );
                  statement = connection.createStatement();
      			}
      		catch ( SQLException sqlException ) {
         		JOptionPane.showMessageDialog( null, sqlException.getMessage(), 
            		"Database Error", JOptionPane.ERROR_MESSAGE );
                  System.exit( 1 );
      			}
      
            catch ( ClassNotFoundException classNotFound ) {
         		JOptionPane.showMessageDialog( null, classNotFound.getMessage(), 
            	"Driver Not Found", JOptionPane.ERROR_MESSAGE );            
         		System.exit( 1 );
     			 }
   		} 
   		
   		//  close database
   public  void terminate() 
   {
       try {
            statement.close();
            connection.close();            
         }
         
         // handle exceptions closing statement and connection
         catch ( SQLException sqlException ) {
            JOptionPane.showMessageDialog( null, 
               sqlException.getMessage(), "Database Error", 
               JOptionPane.ERROR_MESSAGE );
         
            System.exit( 1 );
         }
   } // end method 
   
   		 public void DisplayRecord()
   			{
   		   		if ( ! not.getText().equals( "" ) ) {
                      try {
         			   
                         String sqlString = "select * from people ,work,department"+ " where people.no='"+not.getText() 
                         + "' and people.no=work.no and work.wno=department.wno";
                          
            			ResultSet resultSet =statement.executeQuery( sqlString)  ;
            		
           				 if ( resultSet.next() ) {
                		not.setText(resultSet.getString( 1 )) ;
                		namet.setText(resultSet.getString( 2 ) );
                		sext.setText(resultSet.getString( 3 )) ;
                		addresst.setText(resultSet.getString( 4 ) );
                		polityt.setText(resultSet.getString( 5 )) ;
                
               	     	healtht.setText(resultSet.getString( 6 ) );
                		compactt.setText(resultSet.getString( 7 )) ;
                		
                		
                		
                		wnot.setText(resultSet.getString( 9 ) );
                		           		             		
                	    
                		work1t.setText(resultSet.getString( 10 ));
                		work2t.setText(resultSet.getString( 11 ));
                		work3t.setText(resultSet.getString( 12 ));
                		
                		wnamet.setText(resultSet.getString(14));
                	          			
                		/**/
            			
            			}    
           				 else
            			{
                			
                 			not.setText("");
               				namet.setText("");
               				not.setText("");
               				sext.setText("");
               				addresst.setText("");
               				polityt.setText("");
               				healtht.setText("");
               				compactt.setText("");
                			wnot.setText("");
                			wnamet.setText("");
                			work1t.setText("");
                			work2t.setText("");
                			work3t.setText("");
                			JOptionPane.showMessageDialog( this, 
                  			"Not fund this record!", "Find Result", 
                    		JOptionPane.INFORMATION_MESSAGE ); 
            			}     
                             
         		} // end try

         // process invalid age number format
         		catch ( NumberFormatException formatException ) {
            		JOptionPane.showMessageDialog( this,
               		"Bad age number ", "Invalid Number Format",
               		JOptionPane.ERROR_MESSAGE );
         		}

         // process exceptions from sql
         		catch (SQLException ee)
				{   System.out.println(ee);	} 
	  		}  //end of if sno field value is not empty
		
	  	else //if sno field value is  empty
            	JOptionPane.showMessageDialog( this,
               "Bad sno number ", "Invalid Number Format",
               JOptionPane.ERROR_MESSAGE );
     	
   		}
   		
   	
	
	public static void main(String avgs[])
	{
		new select();
	//	setSize(420,400);
	//	setVisible(true);
	
	}
	
}

⌨️ 快捷键说明

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