以下是 java 中的代码片段,用于从数据库表中获取电子邮件和密码。
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
中的电子邮件与密码分开?
最佳答案
String email= rs.getString("email");
使用 regExpression 拆分“电子邮件”。可能是“.com”、“.org”等,
关于java - 从集合中分离 2 列的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10286476/