java login screen and Mysql database

Asked

Viewed 936 times

-3

I am validating the login of a simple system but giving an error does not login I will send you the code of the class and the moment I try to log in.

Lojabd class that validates the user classe LojaBD que faz a validação do usuário

class that does the login test inserir a descrição da imagem aqui

error that this generating. inserir a descrição da imagem aqui

updated errorinserir a descrição da imagem aqui

  • 5

    Please do not post code as image and do the [tour].

2 answers

1


The error already says it all. You can’t make one run SELECT in a executeUpdate. Use a executeQueryin this case. Change your code to:

String query = "SELECT * FROM userloja WHERE email = ? AND senha = ?";
PreparedStatement ps = conectarMysql().prepareStatement(query);
ps.setString(1, loja.getEmail());
ps.setString(2, loja.getSenha());
ResultSet rs = ps.executeQuery();
return rs.isBeforeFirst();

executeQuery

Executes the SQL query in this Preparedstatement Object and Returns the Resultset Object generated by the query.

In free translation:

Executes the SQL query in the Preparedstatement object and returns a Resultset object generated by this query.

  • take a look at the answer I gave in my own question

  • still giving error in Return

  • it does not identify the resultset Return.isBeforeFirst(); the lapada is asking to create a resultset class

  • I’ve done it and it didn’t work, same mistake

  • have any way to contact Voce? facebook, wpp, skype sla

  • sera pq is a bool method?

  • my comrade I’ve already put the ; never forget to put

  • I put the print of the question

  • vlw that I did not know, obg for the help and sorry for the work I gave

Show 4 more comments

0

The problem is that you are not using JDBC correctly. You should use executeQuery instead of executeUpdate to perform Selects.

ResultSet rs = alterar.executeQuery(query);

Here is a more detailed example of how it should be done.

Browser other questions tagged

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