Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.border.EmptyBorder;
- import java.awt.Font;
- public class StaffLoginPage extends JFrame {
- private JPanel contentPane;
- private JTextField textField;
- private JTextField textField_1;
- private JTextField textField_2;
- private JTextField textField_3;
- private JTextField textField_4;
- private JTextField textField_5;
- private JTextField textField_6;
- private JPasswordField passwordField;
- public static String e_name;
- public static String e_password;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- StaffLoginPage frame = new StaffLoginPage();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- Connection conn=null;
- ResultSet rs,rs1;
- /**
- * Create the frame.
- */
- public StaffLoginPage() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 480, 328);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblStaffLoginPage = new JLabel("STAFF DETAILS");
- lblStaffLoginPage.setHorizontalAlignment(SwingConstants.CENTER);
- lblStaffLoginPage.setFont(new Font("Times New Roman", Font.BOLD, 20));
- lblStaffLoginPage.setBounds(0, 0, 197, 27);
- contentPane.add(lblStaffLoginPage);
- JLabel lble_id = new JLabel("e_id");
- lble_id.setFont(new Font("Trebuchet MS", Font.BOLD, 15));
- lble_id.setBounds(10, 121, 66, 14);
- contentPane.add(lble_id);
- JLabel lble_name = new JLabel("e_name");
- lble_name.setFont(new Font("Trebuchet MS", Font.BOLD, 15));
- lble_name.setBounds(10, 146, 66, 14);
- contentPane.add(lble_name);
- JLabel lble_address = new JLabel("e_address");
- lble_address.setFont(new Font("Trebuchet MS", Font.BOLD, 15));
- lble_address.setBounds(10, 171, 77, 14);
- contentPane.add(lble_address);
- JLabel lble_phoneno = new JLabel("e_phoneno");
- lble_phoneno.setFont(new Font("Trebuchet MS", Font.BOLD, 15));
- lble_phoneno.setBounds(10, 196, 84, 14);
- contentPane.add(lble_phoneno);
- JLabel lble_emailid = new JLabel("e_emailid");
- lble_emailid.setFont(new Font("Trebuchet MS", Font.BOLD, 15));
- lble_emailid.setBounds(10, 221, 77, 14);
- contentPane.add(lble_emailid);
- JLabel lble_salary = new JLabel("e_salary");
- lble_salary.setFont(new Font("Trebuchet MS", Font.BOLD, 15));
- lble_salary.setBounds(10, 246, 77, 14);
- contentPane.add(lble_salary);
- textField = new JTextField();
- textField.setBounds(116, 123, 160, 14);
- contentPane.add(textField);
- textField.setColumns(10);
- textField_1 = new JTextField();
- textField_1.setBounds(116, 146, 160, 17);
- contentPane.add(textField_1);
- textField_1.setColumns(10);
- textField_2 = new JTextField();
- textField_2.setBounds(116, 173, 160, 14);
- contentPane.add(textField_2);
- textField_2.setColumns(10);
- textField_3 = new JTextField();
- textField_3.setBounds(116, 198, 160, 14);
- contentPane.add(textField_3);
- textField_3.setColumns(10);
- textField_4 = new JTextField();
- textField_4.setBounds(116, 221, 160, 13);
- contentPane.add(textField_4);
- textField_4.setColumns(10);
- textField_5 = new JTextField();
- textField_5.setBounds(116, 245, 160, 20);
- contentPane.add(textField_5);
- textField_5.setColumns(10);
- JLabel lblNewLabel = new JLabel("e_name");
- lblNewLabel.setFont(new Font("Traditional Arabic", Font.BOLD, 12));
- lblNewLabel.setBounds(76, 37, 46, 14);
- contentPane.add(lblNewLabel);
- textField_6 = new JTextField();
- textField_6.setBounds(169, 34, 86, 20);
- contentPane.add(textField_6);
- textField_6.setColumns(10);
- JLabel lble_password = new JLabel("e_password");
- lble_password.setFont(new Font("Traditional Arabic", Font.BOLD, 13));
- lble_password.setBounds(76, 62, 66, 14);
- contentPane.add(lble_password);
- passwordField = new JPasswordField();
- passwordField.setBounds(169, 59, 86, 20);
- contentPane.add(passwordField);
- JButton btnSubmit = new JButton("Submit");/*to submit successful login username and password*/
- btnSubmit.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try{Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","AGNI","Agni1234");
- String query="select * from TABLE5 where e_name=? and e_password=?";
- PreparedStatement pst=conn.prepareStatement(query);
- pst.setString(1,textField_6.getText());
- pst.setString(2,passwordField.getText() );
- ResultSet rs=pst.executeQuery();
- int count=0;
- while(rs.next())
- {count=count+1;}
- if(count==1)
- {JOptionPane.showMessageDialog(null,"Username and Password are correct");
- /*String sql="select e_id,e_name,e_address,e_phoneno,e_emailid,e_salary from TABLE5";
- pst=conn.prepareStatement(sql);
- rs1=pst.executeQuery();
- while(rs1.next())
- {textField.setText(rs.getString("e_id"));
- textField_1.setText(rs.getString("e_name"));
- textField_2.setText(rs.getString("e_address"));
- textField_3.setText(rs.getString("e_phoneno"));
- textField_4.setText(rs.getString("e_emailid"));
- textField_5.setText(rs.getString("e_salary"));}*/
- }
- else
- {JOptionPane.showMessageDialog(null,"Username or Password is not valid");}
- rs.close();
- pst.close();
- }
- catch(Exception e1){
- JOptionPane.showMessageDialog(null,e1);
- }
- }
- });
- btnSubmit.setFont(new Font("Trebuchet MS", Font.ITALIC, 13));
- btnSubmit.setBounds(31, 87, 89, 23);
- contentPane.add(btnSubmit);
- JButton btnGetDetail = new JButton("Get Detail");/*to get details of the employee with matching employee username and password from the row of database table*/
- btnGetDetail.addActionListener(new ActionListener() {
- @SuppressWarnings("deprecation")
- public void actionPerformed(ActionEvent e) {
- try{Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","AGNI","Agni1234");
- String sql="select * from TABLE5";
- PreparedStatement pst1=conn.prepareStatement(sql);
- rs1=pst1.executeQuery();
- if(textField_6.getText()==rs1.getString("e_name") && passwordField.getText()==rs1.getString("e_password"))
- {while(rs1.next())
- {textField.setText(rs1.getString("e_id"));
- textField_1.setText(rs1.getString("e_name"));
- textField_2.setText(rs1.getString("e_address"));
- textField_3.setText(rs1.getString("e_phoneno"));
- textField_4.setText(rs1.getString("e_emailid"));
- textField_5.setText(rs1.getString("e_salary"));}
- }
- else
- {JOptionPane.showMessageDialog(null,"NO DATA FOUND");}
- rs1.close();
- pst1.close();
- }
- catch(Exception e2){
- JOptionPane.showMessageDialog(null,e2);
- }
- }
- });
- btnGetDetail.setFont(new Font("Trebuchet MS", Font.ITALIC, 13));
- btnGetDetail.setBounds(166, 89, 130, 23);
- contentPane.add(btnGetDetail);
- }
- }
Add Comment
Please, Sign In to add comment