-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram6.java
More file actions
65 lines (61 loc) · 1.77 KB
/
program6.java
File metadata and controls
65 lines (61 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.awt.Color;
public class program6 implements ActionListener {
JFrame f;
JLabel title, username, password;
JButton login;
JTextField inuser;
JPasswordField inpass;
program6() {
f = new JFrame("Login Authentication Page through JDBC 22EARCS165 ");
title = new JLabel("User Login");
title.setForeground(Color.red);
username = new JLabel("User Name");
password = new JLabel("Password");
inuser = new JTextField();
inpass = new JPasswordField();
login = new JButton("Login");
title.setBounds(200,20,100,20);
username.setBounds(50,50,100,50);
password.setBounds(50,100,100,50);
inuser.setBounds(150,70,200,20);
inpass.setBounds(150,110,200,20);
login.setBounds(200,200,80,20);
f.add(title);
f.add(username);
f.add(password);
f.add(inuser);
f.add(inpass);
f.add(login);
f.setSize(500,350);
f.setLayout(null);
f.setVisible(true);
f.setResizable(false);
login.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
try
{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/logintable", "root", "password");
Statement stmt = con.createStatement();
String sql = "Select *from usertable where user_name='"+inuser.getText()+"' and user_pass = '"+inpass.getText()+"'";
ResultSet rs = stmt.executeQuery(sql);
if(rs.next())
JOptionPane.showMessageDialog(f, "Login successful");
else
JOptionPane.showMessageDialog(f, "Please, check your name and password.");
con.close();
}
catch(Exception ea)
{
System.out.print(ea);
}
}
public static void main(String[] args) {
new program6();
}
}