Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page import="java.sql.*"%>
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="UTF8"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <title>Insert title here</title>
- </head>
- <body>
- <%
- String name=request.getParameter("username");
- String pass=request.getParameter("password");
- if (name.equals("zohar") && pass.equals("123"))
- {
- session.setAttribute("EnterSite","ok");
- response.sendRedirect("homepage.jsp");
- }
- else if (name.equals("zohar") && pass.equals("1234"))
- {
- session.setAttribute("EnterSite","manager");
- response.sendRedirect("homepage.jsp");
- }
- else
- {
- try {// שלב א: טעינת המתפעל - דרייבר
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- //שלב ב:חיבור למסד הנתונים
- Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/members", "root", "MyNewPass");
- //שלב ג: יצירת עצם הסטיטמנט "שידבר" עם מסד הנתונים,
- Statement st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
- // Statement st = con.createStatement(); // כאשר אין פרמטרים, אז אי אפשר לנוע למעלה - למטה בתוך הרזלטסט
- String s = request.getParameter("username");
- String mySQL = "SELECT * FROM allusers WHERE username='" + s + "'";
- //שלב ה: יצירת הרזלטסט - טבלה המחזיקה בתוכה חלק מ-(לפעמים את כל) מסד הנתונים
- ResultSet oRS = st.executeQuery(mySQL);
- //=====================סוף ההתחברות למסד הנתונים======================
- if (oRS.next())
- {
- session.setAttribute("EnterSite","ok");
- response.sendRedirect("homepage.jsp");
- %>
- <script type = text/javascript>
- window.alert("נכנסת בהצלחה");
- </script>
- <%
- }
- else
- {
- session.setAttribute("EnterSite","notok");
- response.sendRedirect("homepage.jsp");
- %>
- <script type = text/javascript>
- window.alert("אתה לא משתמש רשום");
- </script>
- <%
- }
- }
- catch (Exception e) {
- System.out.println(e.getMessage());
- System.out.println("Error in connecting");
- out.println("Error in connecting");
- } // the connection is closed
- }
- finally
- {
- session.setAttribute ("EnterSite","notok");
- }
- %>
- </body>
- </html>
Add Comment
Please, Sign In to add comment