0

Following is the snippet in java that fetches the Email and Password from the database table.

        hashedPassword = encrypter.hashPassword(UserPassword);
        Context context = new InitialContext();
        DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/photog");
        Connection connection = ds.getConnection();
        String sqlStatement = "SELECT email,firstname FROM registrationinformation WHERE password='" + hashedPassword + "'";
        PreparedStatement statement = connection.prepareStatement(sqlStatement);
        ResultSet set = statement.executeQuery();

The above statements execute successfully but how do I separate the email from password that is there in the set ?

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

2 Answers2

2
String email= rs.getString("email");

Spilt "email" with regExpression. may be ".com", ".org" etc.,

kosa
  • 65,990
  • 13
  • 130
  • 167
  • what will `rs.getString("email")` return ? – Suhail Gupta Apr 23 '12 at 19:10
  • It returns email field you have in database. Read this link for more information http://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html – kosa Apr 23 '12 at 19:11
  • so you mean executing the sql statement `rs.getString(...)` will return me the value of any column that belongs to the row executed ? – Suhail Gupta Apr 23 '12 at 19:16
  • Not any column. Input to getString(...) should be one of list you specified in select list in your query (in this case email,firstname) and corresponding data type should be Varchar in database for that field (that means email should be varachar type in database). – kosa Apr 23 '12 at 19:21
  • then why do i need to split email ? – Suhail Gupta Apr 23 '12 at 19:23
  • You said email & password, my assumption was you might be getting email and password in same field. You need to be more clear on what you are expecting. My answer was based on assumption. – kosa Apr 23 '12 at 19:27
0
while(set.next()) {
   email = rs.getString("email");
}

Also check this SO post

Community
  • 1
  • 1
Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328