2016-10-31 4 views
-3
PreparedStatement ps=Database.con.prepareStatement("select * from account where accountno='"+accno+"' and password= '" +pass+ "'"); 
     ResultSet rs=ps.executeQuery(); 
     PreparedStatement ps1=Database.con.prepareStatement("select * from apass where accountno='"+accno+"' and OTP= '" +pass+ "'"); 
     ResultSet rs1=ps1.executeQuery(); 
     PreparedStatement ps2=Database.con.prepareStatement("select * from account where accountno='"+accno+"'"); 
     ResultSet rs2=ps2.executeQuery(); 
     if(rs.next()) 
     { 
     session.setMaxInactiveInterval(300); 
     session.setAttribute("name",rs.getString("full_name")); 
     session.setAttribute("mbno",rs.getString("mobileno")); 
     session.setAttribute("pass",rs.getString("password")); 
     session.setAttribute("accno",rs.getString("accountno")); 
     response.sendRedirect("PBank.jsp"); 
     } 
     if(rs2.next()) 
     { 
      String pas=rs2.getString(6); 
      if(pas==null) 
      { 
       response.sendRedirect("login.jsp?messageInactive=You have deactivated your account, kindly activate your account to login!!"); 
      } 
     } 
     if(rs1.next()) 
     { 
      session.setAttribute("accno",rs1.getString("accountno")); 
      session.setAttribute("pass",rs1.getString("OTP")); 
      response.sendRedirect("reset.jsp"); 
     } 
     if(pass.equals(passs) && accno.equals(acc)) 
     { 
      session.setAttribute("passs",passs); 
      session.setAttribute("acc",acc); 
      response.sendRedirect("admin.jsp"); 
     } 
     else 
     { 
      response.sendRedirect("login.jsp?message=Incorrect Account Number or Password!!!"); 
     } 

答えて

0

次のように構築物を使用し:

try (PreparedStatement ps = Database.con.prepareStatement(
       "select full_name, mobileno, password, accountno " 
       + "from account where accountno=? and password=?")) { 
     ps.setInt(1, accno); 
     ps.setString(2, pass); 
     try (ResultSet rs = ps.executeQuery()) { 
      if (rs.next()) { 
       session.setMaxInactiveInterval(300); 
       session.setAttribute("name",rs.getString("full_name")); // Or (1) 
       session.setAttribute("mbno",rs.getString("mobileno"));// Or (2) 
       session.setAttribute("pass",rs.getString("password")); // pass 
       session.setAttribute("accno",rs.getString("accountno")); // accno 
       response.sendRedirect("PBank.jsp"); 
       return; 
      } 
     } 
    } 
  • をPreparedStatementのSQL injectionを防止し'などをエスケーププレースホルダ?有します。そして、あなたは型を使うことができます。
  • try-with-resourcesそのclose例外とリターンでも自動的に文と結果が設定されます。
  • ここで、SQL select *は問題ありませんが、リストの方が制限された数の列を選択するほうが効率的です。
  • パスワード処理:属性として保存しない方がよいまた、トピック(SQL PASSWORD、java)のビットを検索します。
  • 例文は順番に考案されていますがこのようにして、彼らは最短時間で、そして最小限の並列性を保ちます。データベース側のハンドル数を減らします。
関連する問題