Some help with java beans here !!
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package beans;
import java.sql.*;
/**
*
* @author Sarat.M.R
*/
public class lcbean {
String username, password;
String DBusername = "";
String DBpassword = "";
public String getDBpassword() {
return DBpassword;
}
public void setDBpassword(String DBpassword) {
this.DBpassword = DBpassword;
}
public String getDBusername() {
return DBusername;
}
public void setDBusername(String DBusername) {
this.DBusername = DBusername;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int authentication()
{
//System.out.println(username);
//System.out.println(password);
try {
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/CB", "sarath", "qwerty");
Statement st = con.createStatement();
ResultSet rst= st.executeQuery("select * from table1");
while(rst.next())
{
DBusername=rst.getString("username");
DBpassword=rst.getString("password");
System.out.println(username);
System.out.println(password);
System.out.println(DBusername);
System.out.println(DBpassword);
if((username.equals(DBusername) && password.equals(DBpassword)))
{
System.out.println("I am in if ");
return 0;
}
}
} catch (Exception e) {
System.out.println("Error in lc bean's authentication validation function \n" + e);
}
return 2;
}
}
THIS IS THE CODE I WTITTEB FOR USER AUTHENTICATION FOR MY JSP PROJECT ::
EVERY THING WORKS FINE EXCEPT "IF CONDITION" !!
THE VARIABLES ARE GETTING THE RIGHT VALUES IN THE LOOP BUT THE IF CONDITION SIMPLY DOESN'T WORKS , I DONT KNOW Y IS THIS HAPPENING!!
IT ALWAYS RETURNS THE VALUE '2'
PLEASE HELP ME WITH YOUR VALUABLE SUGESSIONS GUYZZZ..
: -JavaBee
Re: Some help with java beans here !!
Don't double post. The other thread you started in the Advanced Java section has been removed.
db
Re: Some help with java beans here !!
1. Please use [code] tags [/code] when posting code, otherwise it's very hard to follow.
2. Please don't use all caps. That's the internet equivalent of shouting, and you come across like a madman.
Show us the output from a run of this code.
Also, your query should be doing this work. There should be no need to get all the user data back from the database and then loop over it to find out if a username and password match.