我正在使用以下代码,我正在尝试将新用户插入数据库
if(!userText.getText().equals("") && !passwordText.getText().equals(""))
{
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/Poo";
String user="root";
String pass="";
Connection cn=DriverManager.getConnection(url,user,pass);
System.out.println("connected");
Statement st=cn.createStatement();
ResultSet rs=st.executeQuery("select ID,Name,Password from Users");
while(rs.next()){
if (userText.getText().equals(rs.getString("Name"))
&& passwordText.getText().equals(rs.getString("Password")))
{
System.out.println("Correct");
user=rs.getString("Name");
id=Integer.parseInt(rs.getString("ID"));
l2.setForeground(Color.green);
l2.setText("Authentication Successful");
Thread.sleep(2500);
break;
}
else{
l2.setForeground(Color.red);
l2.setText("Wrong Username or Password!");
}
}
}catch(Exception f){System.out.println(f.getMessage());}
System.out.println(userText.getText()+" " +passwordText.getText());
}
关于执行界面冻结,我看不到2500毫秒的“成功”,有什么想法吗?