2012-04-23 68 views
0

以下是java中的代碼段,它從數據庫表中提取電子郵件地址密碼從該集合中分離出2列的值?

 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(); 

上述語句成功執行,但我怎麼分開密碼的電子郵件是那裏的set

回答

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

用regExpression溢出「email」。可能是 「.COM」, 「org」 的等等,

+0

會有什麼'rs.getString( 「電子郵件」)'返回? – 2012-04-23 19:10:24

+0

它返回數據庫中的電子郵件字段。閱讀此鏈接獲取更多信息http://docs.oracle.com/javase/tutorial/jdbc/basics/retrieving.html – kosa 2012-04-23 19:11:39

+0

所以你的意思是執行sql語句'rs.getString(...)'將返回值屬於該行執行的任何列? – 2012-04-23 19:16:09

0
while(set.next()) { 
    email = rs.getString("email"); 
} 

還要檢查this SO post