Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page language="java" import="java.sql.*" errorPage="" %>
- <%@ page import ="javax.sql.*" %>
- <%
- Connection conn = null;
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/kiki", "root", "kim");
- ResultSet rssignin = null;
- PreparedStatement pssignin = null;
- String username = request.getParameter("username");
- String password = request.getParameter("password");
- String message = "User login successfully ";
- try {
- String sqlOption = "SELECT * FROM user where username =? and password =(?)";
- pssignin = conn.prepareStatement(sqlOption);
- pssignin.setString(1, username);
- pssignin.setString(2, password);
- rssignin = pssignin.executeQuery();
- if (rssignin.next()) {
- session.setAttribute("username", rssignin.getString("username"));
- session.setAttribute("username", username);
- response.sendRedirect("home.jsp?error=" + message);
- } else {
- message = "No user or password matched";
- response.sendRedirect("kim.jsp?error=" + message);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- /// close object and connection
- try {
- if (pssignin != null) {
- pssignin.close();
- }
- if (rssignin != null) {
- rssignin.close();
- }
- if (conn != null) {
- conn.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- %>
Add Comment
Please, Sign In to add comment