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

📄 inq.java

📁 JAVA职工信息查询
💻 JAVA
字号:
import javax.swing.*; 
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.sql.*;
import com.bruceeckel.swing.*;

public class inq extends JApplet {
   static Statement s;
   static Connection conn;
   static ResultSet r;
   JLabel tt = new JLabel("职工信息查询");
   JTextField empNO = new JTextField(4);
   JTextField eName = new JTextField(10);
   JTextField job = new JTextField(9);
   JTextField mgr = new JTextField(4);
   JTextField hireDate = new JTextField(10);
   JTextField sal = new JTextField(7);
   JTextField comm = new JTextField(7);
   JTextField deptNO = new JTextField(2);
   JLabel lblEmpNO =  new    JLabel("    职工号");
   JLabel lblEName = new     JLabel("  职工姓名");
   JLabel lblJob = new       JLabel("      工作");
   JLabel lblMgr = new       JLabel("  主管经理");
   JLabel lblHireDate = new  JLabel("  雇用日期");
   JLabel lblSal = new       JLabel("      工资");
   JLabel lblComm = new      JLabel("      备注");
   JLabel lblDeptNO = new    JLabel("  部门编号");
   boolean recOK = false;
   //JTextArea results = new JTextArea(40, 20);
   ActionListener al1 = new ActionListener(){
      public void actionPerformed(ActionEvent e){
      	 String name = ((JButton)e.getSource()).getText();
      	 try{
         	 if (name=="Next"){
         	    recOK = r.next();
         	    if(!recOK) recOK = r.last();
         	 }else if(name=="Previous"){
    	    	  recOK = r.previous();
    	    	  if(!recOK) recOK = r.first();
     	     }else if(name == "Top"){
      	 	    recOK = r.first();
      	   }else if(name == "Bottom"){
      	 	    recOK = r.last();
      	   }
      	   if(recOK)displayRecord();
         }catch(Exception err){
           tt.setText(err.toString());
      	 }
      }
   };
   
   protected void displayRecord(){
   	  try{
         empNO.setText(r.getString("EMPNO"));
         eName.setText(r.getString("ENAME"));
         job.setText(r.getString("JOB"));
         mgr.setText(r.getString("MGR"));
         hireDate.setText(r.getString("HIREDATE"));;
         sal.setText(r.getString("SAL"));
         comm.setText(r.getString("COMM"));
         deptNO.setText(r.getString("DEPTNO"));
      }catch(Exception e){
      	 tt.setText(e.toString());
      }
   }

   public void init() {
      //searchFor.getDocument().addDocumentListener(new SearchL());
      Container cp = getContentPane();
      
      JPanel tp = new JPanel();
      //JLabel tt = new JLabel("职工信息查询");
      tp.add(tt);
      cp.add(BorderLayout.NORTH,tp);

      JPanel jp1 = new JPanel();
      jp1.setLayout(new GridLayout(4,4));
      jp1.add(lblEmpNO);
      jp1.add(empNO);
      jp1.add(lblEName);
      jp1.add(eName);
      jp1.add(lblJob);
      jp1.add(job);
      jp1.add(lblMgr);
      jp1.add(mgr);
      jp1.add(lblHireDate);
      jp1.add(hireDate);
      jp1.add(lblSal);
      jp1.add(sal);
      jp1.add(lblComm);
      jp1.add(comm);
      jp1.add(lblDeptNO);
      jp1.add(deptNO);
      cp.add(BorderLayout.CENTER,jp1);
      JPanel jp2 = new JPanel();
      JButton prev = new JButton("Previous");
      JButton next = new JButton("Next");
      JButton top = new JButton("Top");
      JButton bottom = new JButton("Bottom");
      prev.addActionListener(al1);
      prev.addActionListener(al1);
      next.addActionListener(al1);
      top.addActionListener(al1);
      bottom.addActionListener(al1);
      
      jp2.add(prev);
      jp2.add(next);
      jp2.add(top);
      jp2.add(bottom);
      cp.add(BorderLayout.SOUTH, jp2);
      
      try {
         DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
         //conn = DriverManager.getConnection(
         //       "jdbc:oracle:thin:@terminator:1521:javaORA",
                //"jdbc:oracle:oci:@javaORA",
         //       "scott",
         //       "tiger"
         //);
         /*
         Connection conn = DriverManager.getConnection(
              "jdbc:oracle:thin:"
            + "@(description=(address=(host=terminator)"
            + "(protocol=tcp)(port=1521))(connect_data=(sid=javaORA)))",
              "scott",
              "tiger"
         );
         */
         conn = DriverManager.getConnection(
            "jdbc:oracle:thin:scott/tiger@192.168.0.11:1521:ORADATA"
         );
         s = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
         //s.setFetchSize(1);
         r = s.executeQuery("SELECT empno, ename, job, mgr, hiredate, sal, comm, deptno from emp");
         if(r.next())displayRecord();
      } catch(Exception e) {
      	tt.setText(e.toString());
      }
   }
   public static void main(String[] args) {
      Console.run(new inq(), 500, 200);
   }
}

⌨️ 快捷键说明

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