rjohn5854's Profile User Rating: -----

Reputation: 3 Apprentice
Group:
Active Members
Active Posts:
171 (0.15 per day)
Joined:
04-October 11
Profile Views:
3,684
Last Active:
User is offline Feb 26 2013 11:38 AM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Mac
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
Who Cares
Your Car:
Who Cares
Dream Kudos:
0
Icon   rjohn5854 has not set their status

Posts I've Made

  1. In Topic: How to get the corresponding password using the given Email id

    Posted 26 Feb 2013

    No clue, I fixed the logic. Now, it's returning the password from the database. But, I still feel the program logic can get a lot better than this one.

    Any clue, How I can write a more efficient logic ? making use the User class?

    package com.rony.forgotpass;
    
    public class ForgotPass {
    
    	public static void main(String[] args) {
    
    		String password = (String) Forgotit.forgotpass("lin@yahoo.co.in");
    		
    		System.out.println(password);
    	}
    }
    
    
    


    package com.rony.forgotpass;
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    
    public class Forgotit {
    
    	static Connection conn = null;
    	static PreparedStatement ps = null;
    	static ResultSet rs = null;
    
    	public static String forgotpass(String email) {
    
    		String sql = "SELECT password FROM User WHERE email='" + email + "'";
    
    		try {
    			conn = DBUtil.getConnection();
    
    			if (conn != null) {
    				ps = conn.prepareStatement(sql);
    				rs = ps.executeQuery();
    
    				while (rs.next()) {
    					String password = rs.getString("password");
    
    					return password;
    				}
    
    			}
    
    		} catch (SQLException e) {
    			e.printStackTrace();
    		} finally {
    			DBUtil.closeConnection();
    
    		}
    		return null;
    
    	}
    
    }
    
    
    


    package com.rony.forgotpass;
    
    public class User {
    	
    	private String forgotEmail;
    
    	public String getForgotEmail() {
    		return forgotEmail;
    	}
    
    	public void setForgotEmail(String email) {
    		this.forgotEmail = email;
    	}
    
    }
    
    
    

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Years Programming:
1
Programming Languages:
Mainily work on Java/J2EE and Front-end stuff.

Contact Information

E-mail:
Private

Friends

Comments

rjohn5854 has no profile comments yet. Why not say hello?