2014-04-27 35 views
-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; 
           } 
          } 
+0

顯示*確切的錯誤文本*。還有你的表格定義和PostgreSQL版本。 –

回答

0

乍一看,您有:

Connection conn = null; 
PreparedStatement statement = conn.prepareStatement("SELECT * FORM UserAccount"); 

嘗試用正確的連接。

0

有一個在PreparedStatement的語法錯誤,你在select語句應該從書面形式。確切的語法是

Connection conn=null; 
PreparedStatement statement=conn.prepareStatement("SELECT * FROM UserAccount");