Results 1 to 3 of 3
  1. #1
    javaBee is offline Member
    Join Date
    Jan 2012
    Posts
    12
    Rep Power
    0

    Angry 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

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default 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
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default 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.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. How to make Beans Lazily-instantiating beans
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-30-2008, 11:10 AM
  2. How to make Beans Lazily-instantiating beans
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 09-26-2007, 09:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •