1
btnLogIn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try { Connection lig = DriverManager.getConnection(
"jdbc:mysql://localhost/gym", "root", "");
PreparedStatement inst = lig .prepareStatement(
"SELECT * FROM contauser WHERE Username=? AND Password=?");
inst.setString(1, txtUser.getText());
char[] Password=txtPass.getPassword();
inst.setString(2, new String(Password));
int linhas = inst.executeUpdate();
lig.close(); if (linhas == 1) {
JOptionPane.showMessageDialog(frame, "Logged in");
CardLayout card = (CardLayout) frame.getContentPane()
.getLayout();
card.show(frame.getContentPane(), "MenuPrincipal");
}
else JOptionPane.showMessageDialog(frame,
("Invalid username or password"));
} catch (SQLException e1) {
JOptionPane.showMessageDialog(frame,
"Impossível ligar à base de dados");
System.out.println(e1.getLocalizedMessage());
}
}
});
*error
Can not Issue executeUpdate() for Selects
Hello. Welcome to SOPT. Yours is very confusing. See here how to ask .
– Omni
Change
executeUpdate()
forexecuteQuery()
.executeUpdate()
is used to execute a command of type UPDATE, INSERT or DELETE and not a SELECT.– ramaral
Thanks ramaral, already works.
– Sancho
@ramaral turn into response :)
– Maicon Carraro
@Maiconcarraro I believe that, as the question is asked, my answer will not help anyone else besides the AP. There are even votes to close that should be for that reason.
– ramaral
But it is still an answer and in this case the right one for the author. :)
– Maicon Carraro