Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Login button
- JButton btnNewButton = new JButton("Login");
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0)
- {
- try {
- // connection to databse
- Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/myusers", "root", "root");
- String query = "select * from brugere where username=? and password=?";
- PreparedStatement myStnt = myConn.prepareStatement(query);
- myStnt.setString(1, textField.getText());
- myStnt.setString(2, passwordField.getText());
- //// Create statement
- ResultSet myRs = myStnt.executeQuery();
- //
- int count = 0;
- while (myRs.next()) {
- count = count + 1;
- }
- if (count == 1) {
- myRs.close();
- myStnt.close();
- myConn.close();
- MainMenu mm = new MainMenu();
- mm.setVisible(true);
- frame.dispose();
- frame.dispose();
- }
- else if (count > 1)
- {
- JOptionPane.showMessageDialog(null, "Duplicate Username and password");
- }
- else
- {
- JOptionPane.showMessageDialog(null, "Sorry wrong username or password");
- }
- }catch (Exception e){
- JOptionPane.showMessageDialog(null, e);
- }
- }
- });
- btnNewButton.setBounds(288, 96, 89, 67);
- frame.getContentPane().add(btnNewButton);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement