Results 1 to 6 of 6
- 10-14-2011, 12:44 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 76
- Rep Power
- 0
- 10-14-2011, 01:08 AM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: Question about ResultSetMetadata methods
A simple select query should tell you if the username/password combination is within the database. See the API for ResultSetMetaData - it provides meta data associated with a query, you retrieve the results of a query through a ResultSet.
- 10-14-2011, 01:13 AM #3
Member
- Join Date
- Jul 2011
- Posts
- 76
- Rep Power
- 0
Re: Question about ResultSetMetadata methods
if i were to just use a simple select query what would be returned if the username and password was not found
- 10-14-2011, 01:51 AM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,609
- Rep Power
- 5
Re: Question about ResultSetMetadata methods
Did you try it? What happened?
- 10-14-2011, 07:25 AM #5
Member
- Join Date
- Jul 2011
- Posts
- 76
- Rep Power
- 0
Re: Question about ResultSetMetadata methods
what i did was to create two local variables name userName and password. Then i used the userName and password supplied has the criteria for my search. I then store the result of the search in the local username and password variables. then i do a comparision to to find out if the username in the database matched the entered
what is want to know is if i could have just done the search without creating the local variables and use the resultset metadata to find out if the username and password is in the databaseJava Code:public boolean log () { String userName = "",password = ""; try { Connection con = DriverManager.getConnection ("jdbc:mysql://localhost/database", "root",""); Statement state = con.createStatement (); ResultSet rs = state.executeQuery("SELECT userName,password FROM userTable WHERE userName='" + this.userName + "'"); while (rs.next()) { userName = rs.getString("userName"); password = rs.getString("password"); } catch (SQLException e) { System.out.println (e.getMessage()); } if (this.userName.equal(userName) && this.password.equals (password)) return true else return false; }
- 10-14-2011, 08:30 AM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: Question about ResultSetMetadata methods
I'd do something like this: make the db return a single 1 if the username and password match; if they don't match the ResultSet is empty and you know enough; there is no need to transfer a correct password over the wire ...
kind regards,Java Code:select 1 from userTable where username = ? and password = ?
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Question concerning methods
By jim01 in forum New To JavaReplies: 6Last Post: 05-18-2011, 02:46 PM -
2 methods with same name Question
By dienesh77 in forum New To JavaReplies: 4Last Post: 03-22-2011, 01:58 PM -
Problem with ResultSetMetaData getPrecision and getScale on .DBF files.
By CrOnNoS in forum JDBCReplies: 3Last Post: 10-05-2009, 10:10 AM -
resultsetmetadata
By thamizhisai in forum Advanced JavaReplies: 1Last Post: 05-27-2008, 07:41 AM -
question about abstract methods
By osval in forum New To JavaReplies: 1Last Post: 07-25-2007, 08:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks