Advertisement
Guest User

EMPLOYEE SEARCH CODES

a guest
Jan 27th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. String employeeid=tf6.getText();
  2.     if(employeeid.isEmpty())
  3.     {
  4.         tf7.setText("");
  5.        
  6.         tf9.setText("");
  7.         tf10.setText("");
  8.         JOptionPane.showMessageDialog(this," ENTER ID PLEASE ");
  9.     }
  10.     else
  11.     {
  12.         try
  13.         {
  14.         Class.forName("java.sql.DriverManager");
  15.         Connection con =(Connection)
  16.          DriverManager.getConnection("jdbc:mysql://localhost:3306/project","root","ips");
  17.         Statement stmt=(Statement)con.createStatement();
  18.         String query="SELECT empname,doj ,phoneno FROM EMPLOYEE WHERE empid = '"+ employeeid+"';";
  19.        
  20.         ResultSet rs=stmt.executeQuery(query);
  21.         if(rs.next())
  22.                 {
  23.                     String empname=rs.getString("empname");
  24.                     String doj=rs.getString("doj");
  25.                     String phoneno=rs.getString("phoneno");
  26.                    
  27.                     tf7.setText(empname);
  28.                     tf9.setText(doj);
  29.                     tf10.setText(phoneno);
  30.                    
  31.                 }
  32.         else
  33.             JOptionPane.showMessageDialog(this,"sorry!No such employee id");
  34.        
  35.          
  36.         }
  37.         catch(Exception e)
  38.         {
  39.         JOptionPane.showMessageDialog(this,e.getMessage());    
  40.            
  41.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement