Page 1 of 2 12 LastLast
Results 1 to 20 of 22
  1. #1
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default help!comparing input with sql data.

    i am doing logging in.i want to check user input password with the password stored by the username.how to i do so?i tried this but keep return success = true

    public static boolean loginUser(String inUserName, String inPwd){
    boolean success = false;
    ResultSet rs=null;
    DBController db = new DBController();

    db.setUp("userDatabase");

    String dbQuery = "SELECT Pwd FROM USER WHERE USERNAME ='" + inUserName + "' ";
    rs =db.readRequest(dbQuery);
    try{
    if ((rs.next()) || (inPwd==rs.getString("Pwd"))){
    success = true;
    }
    }
    catch (Exception e){
    e.printStackTrace();
    }
    return success;
    }

  2. #2
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by 10e5x View Post
    Java Code:
    		try{
    			if ((rs.next()) || (inPwd==rs.getString("Pwd"))){
    				success = true;
    			}
    		}
    try using equals()
    Java Code:
    inPwd.equals("Pwd");
    of course, i am assuming you are really checking against the string "Pwd".

  3. #3
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    yes i am. however i use ur suggestion then it always return true.it does not care if my pwd is right or wrong

  4. #4
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by 10e5x View Post
    yes i am. however i use ur suggestion then it always return true.it does not care if my pwd is right or wrong
    why are you using "||" then? This means "or" , so if rs.next() is always evaluated (ie, there is return value from database query), then your "inPwd.equals("Pwd") will not be evaluated.
    Last edited by JavaHater; 01-01-2011 at 06:29 AM.

  5. #5
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    meaning i use &&?cuz i want to check if username is in my database not if not it will not even check if that username's password is equals to the input pwd.anyway, thanks for being so helpful,but i am really stucked for long

  6. #6
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by 10e5x View Post
    meaning i use &&?cuz i want to check if username is in my database not if not it will not even check if that username's password is equals to the input pwd.anyway, thanks for being so helpful,but i am really stucked for long
    why not you just get the string out from the database first , then do the compare? I don't have a database to test, but here's the steps you can do
    Java Code:
    Query the database, and return just the password string ( ie, remove the "|| (inPwd==rs.getString("Pwd"))" line
    check password string against inPwd

  7. #7
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    i believe u mean this?if i remove rs.next(), there will be a error: Invalid cursor states and login in is unsuccessful even though i pass in the correct password.

    public static boolean loginUser(String inUserName, String inPwd){
    boolean success = false;
    ResultSet rs=null;
    DBController db = new DBController();

    db.setUp("userDatabase");

    String dbQuery = "SELECT Pwd FROM USER WHERE USERNAME ='" + inUserName + "' ";
    rs =db.readRequest(dbQuery);
    try{
    if (inPwd==rs.getString("Pwd")){

    success = true;

    }
    }
    catch (Exception e){
    e.printStackTrace();
    }
    return success;
    }

  8. #8
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    help help.

  9. #9
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by 10e5x View Post
    i believe u mean this?if i remove rs.next(), there will be a error: Invalid cursor states and login in is unsuccessful even though i pass in the correct password.

    public static boolean loginUser(String inUserName, String inPwd){
    boolean success = false;
    ResultSet rs=null;
    DBController db = new DBController();

    db.setUp("userDatabase");

    String dbQuery = "SELECT Pwd FROM USER WHERE USERNAME ='" + inUserName + "' ";
    rs =db.readRequest(dbQuery);
    try{
    if (inPwd==rs.getString("Pwd")){

    success = true;

    }
    }
    catch (Exception e){
    e.printStackTrace();
    }
    return success;
    }

    no, do it step by step. Make sure you get back something back first from your database query. Then, do the comparison.

  10. #10
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    i did. my rs.next() works. but once it compares it doesnt. i think i am too not good at it.what do u mean by step by step.meaning i break down which one?if able to, can u kindly show me the codes?

  11. #11
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by 10e5x View Post
    i did. my rs.next() works. but once it compares it doesnt. i think i am too not good at it.what do u mean by step by step.meaning i break down which one?if able to, can u kindly show me the codes?
    so rs.next() works, but what is the result? Can you show the result of the query?

  12. #12
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    result of the qeury is "12345" when i key in inUserName = 10e5x

  13. #13
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by 10e5x View Post
    result of the qeury is "12345" when i key in inUserName = 10e5x
    ok, now show the code where you do the comparison , as well as the code where you get the database result.

  14. #14
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    if (inPwd==rs.getString("Pwd")){

    success = true;

    }

    keep return false and got the error invalid cursor even i enter in the correct password to 10e5x

  15. #15
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    Quote Originally Posted by 10e5x View Post
    if (inPwd==rs.getString("Pwd")){

    success = true;

    }

    keep return false and got the error invalid cursor even i enter in the correct password to 10e5x
    when you print out rs.getString("Pwd"), its 12345 right?

    then you should be able to use inPwd.equals( rs.getString("Pwd") );
    Last edited by JavaHater; 01-01-2011 at 10:12 AM.

  16. #16
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    i solved.really thank you so much.u helped alot

  17. #17
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    SELECT * FROM USER WHERE Email = 'guox@gmail.com' ;
    this sql statement return me every columns but with no value. how come?

  18. #18
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    why don't you show all your code and how you fetch them ?

  19. #19
    10e5x is offline Member
    Join Date
    Nov 2010
    Posts
    33
    Rep Power
    0

    Default

    public static boolean forgetUser(String inEmail, String inDob){
    boolean success = false;
    ResultSet rs=null;
    DBController db = new DBController();

    db.setUp("userDatabase");

    String dbQuery = "SELECT * FROM USER WHERE EMAIL ='" + inEmail + "' ";
    rs =db.readRequest(dbQuery);
    try{
    if (rs.next()){
    if((inEmail.equals( rs.getString("Pwd") )) || (inDob.equals(rs.getString("Dob"))))

    success = true;

    }
    }
    catch (Exception e){
    e.printStackTrace();
    }
    return success;
    }


    the result give me back blank table with all column name

  20. #20
    JavaHater is offline Senior Member
    Join Date
    Dec 2010
    Posts
    165
    Rep Power
    4

    Default

    this is just a function. you are only returning true or false. I don't see any code that displays your result.

Page 1 of 2 12 LastLast

Similar Threads

  1. help with data output, input
    By collin389 in forum New To Java
    Replies: 3
    Last Post: 11-11-2009, 05:34 PM
  2. Collecting ResultSet data and Comparing
    By casid in forum New To Java
    Replies: 4
    Last Post: 06-08-2009, 08:43 PM
  3. Comparing two data types in order to store in array
    By gwithey in forum New To Java
    Replies: 3
    Last Post: 05-01-2009, 10:27 AM
  4. Input data from file to arrays problem
    By PVL268 in forum New To Java
    Replies: 18
    Last Post: 03-16-2009, 05:05 AM
  5. jdbTable() and TableDataSet() data input
    By stingalingaling in forum New To Java
    Replies: 0
    Last Post: 12-26-2008, 06:07 AM

Posting Permissions

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