String sess_user = session.getAttribute("userid").toString();
out.println(sess_user);
try{
String connectionURL = "jdbc:mysql://localhost:3306/books";// books is the database
Connection connection = null;
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(connectionURL, "root", "bonnysingh");
Statement st = connection.createStatement();
ResultSet rs=st.executeQuery("select email from signup where UserName = '" + sess_user +"'");
while(rs.next()){
userEmail = rs.getString(3);
}
}
catch(Exception ee){
out.println(ee);
}
out.println("Hello");
out.println(userEmail);
userEmail的输出始终为null。我不知道这里有什么问题。但我认为while(rs.next())循环没有正确执行。谁能告诉我这是错误的?
答案 0 :(得分:5)
您只选择了一个列,但是您尝试访问结果中的第三个列。
将getString(3)
更改为getString(1)
,您应该没问题。