I have a swing jframe
that has a login screen and I'm trying to execute a phpmyadmin
database query. It connects to the database but it doesn't allow me to log in and just infinity says "invalid username or password" Here is the code.
JPasswordField jpfpass;
JLabel jlabuser, jlabpass;
public RychlikSystemversion0(String name) {
super(name);
btnlogin = new JButton("Login");
btenreset = new JButton("Reset");
btnexit = new JButton("Exit");
jtfuser = new JTextField();
jpfpass = new JPasswordField();
jlabuser = new JLabel("Ussername");
jlabpass = new JLabel("Password");
this.setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
btnlogin.addActionListener(this);
btenreset.addActionListener(this);
btnexit.addActionListener(this);
jlabuser.setBounds(10, 10, 120, 20);
jlabpass.setBounds(10, 30, 120, 20);
jtfuser.setBounds(140, 10, 300, 20);
jpfpass.setBounds(140, 30, 300, 20);
btnlogin.setBounds(140, 55, 100, 20);
btenreset.setBounds(240, 55, 100, 20);
btnexit.setBounds(340, 55, 100, 20);
this.add(jlabuser);
this.add(jlabpass);
this.add(jtfuser);
this.add(jpfpass);
this.add(btnlogin);
this.add(btenreset);
this.add(btnexit);
this.setSize(500, 300);
this.setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
//String USERNAME = "root";
//String PASSWORD = "root ";
//String CONN_STRING = "jdbc:mysql://localhost::3307/osdesign";
Connection connection;
PreparedStatement ps;
try {
String dbName = "osdesign";
String dbUserName = "root";
String dbPassword = "";
//String u = jtfuser.getText();
//String p =jpfpass.getName();
String connectionString = "jdbc:mysql://localhost/" + dbName + "?user="
+ dbUserName + "&password=" + dbPassword
+ "&useUnicode=true&characterEncoding=UTF-8";
connection = DriverManager.getConnection(connectionString);
JOptionPane.showMessageDialog(null, "Connected!");
String sql = "SELECT * FROM `userlist` WHERE `UsrName` = ? AND `UsrPass` = ?";
ps = connection.prepareStatement(sql);
jtfuser.setText("Test");
jpfpass.setText("Test");
ps.setString(1, jtfuser.getText());
ps.setString(2, jpfpass.getName());
//JFrame panel = new JFrame();
ResultSet result = ps.executeQuery();
btnlogin.equals(result);
// panel.add(btnlogin);
// panel.add(jpfpass.getName(),btnlogin);
if (result.next()) {
JOptionPane.showMessageDialog(null, "Login Sucessful"); //Wont execute statement
} else {
JOptionPane.showMessageDialog(null, "Invalid user name or password"); //Always does this
}
} catch (SQLException ex) {
Logger.getLogger(RychlikSystemversion0.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String[] args) {
RychlikSystemversion0 ls = new RychlikSystemversion0("System login");
}
I've tried several things it still doesn't allow me to login. Any help?