Java login/password verification
Solved
ilhem.s
Posted messages
34
Status
Member
-
tarik45 Posted messages 2 Status Member -
tarik45 Posted messages 2 Status Member -
Hello,
I’m trying to set up an authentication page but an exception occurs during execution, here it is:
java.sql.SQLException: Operation not allowed after ResultSet closed
Here is also a part of the code related to the login button
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,log ,password);
Statement S=con.createStatement();
ResultSet resultaltLogin=S.executeQuery("Select login from user;");
while(resultaltLogin.next())
{
String LoginRecup=resultaltLogin.getString("login");
if (login.equals(LoginRecup))
{
ResultSet res=S.executeQuery("Select mot_de_passe from user where login='LoginRecup';");
while(res.next())
{
String MPRecup=res.getString("mot_de_passe");
if(MPRecup.equals(MP))
{
verif=true;
Accueil A=new Accueil();
A.show(true);
dispose();
}
}
}
}
if(!verif)
{
JOptionPane.showMessageDialog(null, "Verifier Login / Mot de passe", "Message d'erreur:"", JOptionPane.ERROR_MESSAGE);
T1.setText("");
PF.setText("");
}
con.close();
} catch(Exception a){System.out.println(a);}
I’m trying to set up an authentication page but an exception occurs during execution, here it is:
java.sql.SQLException: Operation not allowed after ResultSet closed
Here is also a part of the code related to the login button
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,log ,password);
Statement S=con.createStatement();
ResultSet resultaltLogin=S.executeQuery("Select login from user;");
while(resultaltLogin.next())
{
String LoginRecup=resultaltLogin.getString("login");
if (login.equals(LoginRecup))
{
ResultSet res=S.executeQuery("Select mot_de_passe from user where login='LoginRecup';");
while(res.next())
{
String MPRecup=res.getString("mot_de_passe");
if(MPRecup.equals(MP))
{
verif=true;
Accueil A=new Accueil();
A.show(true);
dispose();
}
}
}
}
if(!verif)
{
JOptionPane.showMessageDialog(null, "Verifier Login / Mot de passe", "Message d'erreur:"", JOptionPane.ERROR_MESSAGE);
T1.setText("");
PF.setText("");
}
con.close();
} catch(Exception a){System.out.println(a);}
Related links:
- The Outlook "password required" window keeps popping up.
- How can I receive my Snap security code on my new number?
- How to recover your Snapchat account without email and without the number
- More connection with freewifi secure
- Solution to recover your Snapchat account
- Recover Instagram account without phone number with two-factor authentication
5 answers
-
Hello,
just a small remark,
from an optimization perspective you can avoid running the query twice (the first to retrieve the login and the second to retrieve the password) because you end up connecting to your database twice and executing two queries, so it can slow down your execution, especially if you notice the two queries point to the same table!! (these are just recommendations, it doesn’t prevent your code from being correct), and to do it you do a select * from user after you compare the user-password pairs to what the user enters.
ResultSet resultaltLogin=S.executeQuery("Select * from user;");
while(resultaltLogin.next())
{
String LoginRecup=resultaltLogin.getString("login");
String MPRecup=resultaltLogin.getString("mot_de_passe ");
if (login.equals(LoginRecup) && MPRecup.equals(MP))
{
...... // your processing here
}
try to correct like this maybe that will give something