I am currently working on a simple JDBC project and I am stuck at the login form
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost/company","root","redhat");
stmt=con.createStatement();
String nm=jTextField1.getText();
char[] pass=jPasswordField1.getPassword();
String pw=Arrays.toString(pass);
String sql="select * from login where uname='"+nm+"' and pass='"+pw+"'";
rs=stmt.executeQuery(sql);
if(rs.next())
{
new MainPage().setVisible(true);
this.setVisible(false);
}
else
{
JOptionPane.showMessageDialog(this, "Wrong User name or password");
jTextField1.setText("");
jPasswordField1.setText("");
}
}
catch(Exception e)
{
System.out.println(e);
}
} `
When this button is clicked a new page that I have created is to be shown ,but it shows "Wrong User name or password" message dialog. What are my mistakes? My database is in mysql.
nm+" and "+pwand you will see the difference