eclipse database connection

Asked

Viewed 50 times

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 .

  • Change executeUpdate() for executeQuery(). executeUpdate() is used to execute a command of type UPDATE, INSERT or DELETE and not a SELECT.

  • Thanks ramaral, already works.

  • 1

    @ramaral turn into response :)

  • @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.

  • But it is still an answer and in this case the right one for the author. :)

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.