Results 1 to 20 of 22
- 01-01-2011, 06:05 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
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;
}
- 01-01-2011, 06:11 AM #2
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
- 01-01-2011, 06:16 AM #3
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
yes i am. however i use ur suggestion then it always return true.it does not care if my pwd is right or wrong
- 01-01-2011, 06:27 AM #4
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
- 01-01-2011, 06:29 AM #5
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
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
- 01-01-2011, 06:46 AM #6
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
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
- 01-01-2011, 06:52 AM #7
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
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;
}
- 01-01-2011, 07:40 AM #8
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
help help.
- 01-01-2011, 08:26 AM #9
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
- 01-01-2011, 08:35 AM #10
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
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?
- 01-01-2011, 08:41 AM #11
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
- 01-01-2011, 09:11 AM #12
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
result of the qeury is "12345" when i key in inUserName = 10e5x
- 01-01-2011, 09:34 AM #13
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
- 01-01-2011, 09:38 AM #14
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
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
- 01-01-2011, 10:10 AM #15
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
- 01-01-2011, 01:47 PM #16
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
i solved.really thank you so much.u helped alot
- 01-01-2011, 01:54 PM #17
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
SELECT * FROM USER WHERE Email = 'guox@gmail.com' ;
this sql statement return me every columns but with no value. how come?
- 01-01-2011, 02:18 PM #18
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
why don't you show all your code and how you fetch them ?
- 01-01-2011, 02:49 PM #19
Member
- Join Date
- Nov 2010
- Posts
- 33
- Rep Power
- 0
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
- 01-01-2011, 02:59 PM #20
Senior Member
- Join Date
- Dec 2010
- Posts
- 165
- Rep Power
- 3
Similar Threads
-
help with data output, input
By collin389 in forum New To JavaReplies: 3Last Post: 11-11-2009, 05:34 PM -
Collecting ResultSet data and Comparing
By casid in forum New To JavaReplies: 4Last Post: 06-08-2009, 08:43 PM -
Comparing two data types in order to store in array
By gwithey in forum New To JavaReplies: 3Last Post: 05-01-2009, 10:27 AM -
Input data from file to arrays problem
By PVL268 in forum New To JavaReplies: 18Last Post: 03-16-2009, 05:05 AM -
jdbTable() and TableDataSet() data input
By stingalingaling in forum New To JavaReplies: 0Last Post: 12-26-2008, 06:07 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks