The error happens because the "result" variable is declared in the while loop. You could have something looking like this instead :
Remove the "else" block, because you want to loop through all record before setting the result. You also need to close all resources in a finally block instead of in the try/catch block.
1. It would be easier to make an SQL statement like "select * from details where uname=? and pwd=?" (or whatever the field names are), and use statement.setString(1, name) and statement.setString(2, pwd).
2. The name of your method is confusing. It looks like it just connects to a DB. It looks like name and pwd are values used for the JDBC connection. You should separate the db connection stuff, and the user check stuff in separate methods.