private void loginbutton(JFrame login) {
JPanel login1=new JPanel();//
login1.setLayout(null);
JLabel userlabel1=new JLabel("administrator:");
userlabel1.setBounds(60,20,80,20);
JTextField usertext=new JTextField(10);
usertext.setBounds(150,20,200,20);
JLabel password=new JLabel("password:");
password.setBounds(60,60,80,20);
JPasswordField userpassword=new JPasswordField(10);
userpassword.setBounds(150,60,200,20);
//Object use=usertext.getText();
//Object pass=userpassword.getText();
JButton loginButton = new JButton("login");
loginButton.setBounds(210, 340, 80, 20);
loginButton.addActionListener(e -> {
String url="jdbc:mysql://localhost:3306/test123?useUnicode=true"+
"&userSSL=false&serverTimezone=GMT%2B8";
String user="wsw";
String pwd="123456";
String sql="SELECT * from users";
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn= DriverManager.getConnection(url,user,pwd);
Statement stmt =conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
java.lang.System.out.println("user | pwd");
while(rs.next()){
String administrator=rs.getString("administrator");
String password1 =rs.getString("password");
java.lang.System.out.println(administrator+"|"+ password1);
if(usertext.getText() == administrator&&userpassword.getText()== password1){
new System();
}
}
} catch (Exception a) {
a.printStackTrace();
}
}
);