Guest User

Untitled

a guest
Jan 14th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <%@ page language="java" import="java.sql.*" errorPage="" %>
  2. <%@ page import ="javax.sql.*" %>
  3. <%
  4.  
  5. Connection conn = null;
  6. Class.forName("com.mysql.jdbc.Driver").newInstance();
  7. conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/kiki", "root", "kim");
  8.  
  9. ResultSet rssignin = null;
  10. PreparedStatement pssignin = null;
  11.  
  12. String username = request.getParameter("username");
  13. String password = request.getParameter("password");
  14. String message = "User login successfully ";
  15.  
  16. try {
  17. String sqlOption = "SELECT * FROM user where username =? and password =(?)";
  18.  
  19. pssignin = conn.prepareStatement(sqlOption);
  20. pssignin.setString(1, username);
  21. pssignin.setString(2, password);
  22.  
  23. rssignin = pssignin.executeQuery();
  24.  
  25. if (rssignin.next()) {
  26.  
  27.  
  28. session.setAttribute("username", rssignin.getString("username"));
  29. session.setAttribute("username", username);
  30.  
  31. response.sendRedirect("home.jsp?error=" + message);
  32. } else {
  33. message = "No user or password matched";
  34. response.sendRedirect("kim.jsp?error=" + message);
  35. }
  36. } catch (Exception e) {
  37. e.printStackTrace();
  38. }
  39.  
  40.  
  41. /// close object and connection
  42. try {
  43. if (pssignin != null) {
  44. pssignin.close();
  45. }
  46. if (rssignin != null) {
  47. rssignin.close();
  48. }
  49.  
  50. if (conn != null) {
  51. conn.close();
  52. }
  53. } catch (Exception e) {
  54. e.printStackTrace();
  55. }
  56.  
  57. %>
Add Comment
Please, Sign In to add comment