Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void loginValidation(){
- String str1 = user.getText();
- char[] pwd = pass.getPassword();
- String s = new String(pwd); //converting char to string
- String p = s;
- if("".equals(str1)){
- JOptionPane.showMessageDialog(null, "User Name is Empty", "Login Status", JOptionPane.ERROR_MESSAGE);
- }
- else if((p.length()) == 0)
- {
- JOptionPane.showMessageDialog(null, "Password is Empty", "Login Status", JOptionPane.ERROR_MESSAGE);
- }
- else{
- try{
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hotel","root","root");
- Statement stmt=con.createStatement();
- ResultSet rs=stmt.executeQuery("SELECT * FROM details WHERE USER='" + str1 +"' and PASSWORD='" + p + "'");
- if (rs.next()) {
- this.dispose();
- s1=rs.getString(1);
- f_user=s1;
- s2=rs.getString(2);
- s3=rs.getString(3);
- s4=rs.getString(4);
- s5=rs.getString(5);
- s6=rs.getString(6);
- JOptionPane.showMessageDialog(null, "Login Successfull", "Login Status", JOptionPane.INFORMATION_MESSAGE);
- if (rs.getString(7).equals("admin"))
- {
- this.setVisible(false);
- this.dispose();
- Admin frm = new Admin();
- frm.setVisible(true);
- }
- else if (rs.getString(7).equals("customer"))
- {
- this.setVisible(false);
- this.dispose();
- Customer cus = new Customer();
- cus.setVisible(true);
- }
- else
- {
- this.setVisible(false);
- this.dispose();
- Employee emp = new Employee();
- emp.setVisible(true);
- }
- }
- else{
- JOptionPane.showMessageDialog(null,"Invalid username or password","Invalid",JOptionPane.ERROR_MESSAGE);
- }con.close();
- }catch(Exception e)
- {
- System.out.println(e);
- }
- }
- }
Add Comment
Please, Sign In to add comment