-1
如何驗證JSP中數據庫中是否存在用戶登錄名?我在PreparedStatement語句= conn.prepareStatement(「SELECT * FORM UserAccount」)中不斷收到異常錯誤。使用JSP中的postgresql數據庫驗證用戶輸入
<td><input type = "text" name = "user_name" value = "" /></td>
<%
String thatname = request.getParameter("user_name");
session.setAttribute("theName", thatname);
ResultSet rs = null;
// Verify if the username already exists in the database.
try {
//String userValidate = "SELECT * FORM UserAccount";
Connection conn = null;
PreparedStatement statement = conn.prepareStatement("SELECT * FORM UserAccount");
rs = statement.executeQuery();
while(rs.next()) {
if(thatname == rs.getString("name")) {
// do something
}
}
rs.close();
}catch(SQLException e) {
throw new RuntimeException(e);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) { } // Ignore
rs = null;
}
}
顯示*確切的錯誤文本*。還有你的表格定義和PostgreSQL版本。 –