Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@ page contentType="text/html; charset=iso-8859-1" language="java"
- import="java.sql.*" errorPage="" %>
- <%
- PreparedStatement stmt = null;
- Connection conn = null;
- try {
- //Connect to the database
- Class.forName("oracle.jdbc.driver.OracleDriver");
- String hostname = "localhost";
- int port = 1521;
- String sid = "xe";
- String oracleURL = "jdbc:oracle:thin:@"+hostname+":"+port+":"+sid;
- String user = "system";
- String pass = "system";
- conn = DriverManager.getConnection(oracleURL, user, pass);
- %><script>alert("Your profile has been successfully updated!");</script><%
- //Create an empty new variable
- String message = null;
- String usertype = request.getParameter("usertype");
- String userid = session.getAttribute("userid");
- String username = request.getParameter("username");
- String password = request.getParameter("password");
- String usernamedb = "";
- String useriddb = "";
- if (usertype.equals("student")){
- userid = "S"+userid;
- usernamedb = "student_name";
- useriddb = "student_id";
- }
- else{
- userid = "T"+userid;
- usernamedb = "teacher_name";
- useriddb = "teacher_id";
- }
- // Make the query
- stmt=conn.prepareStatement("update "+usertype+" set "+usernamedb+" = ?, password = ? where "+useriddb+" = ?");
- stmt.clearParameters();
- stmt.setString(1,username);
- stmt.setString(2,password);
- stmt.setString(3,userid);
- //Run the query
- stmt.executeUpdate();
- conn.commit();
- out.println("<p> <b> You have been registered !</b></p>");
- //Close the database connection
- stmt.close();
- conn.close();
- } catch (SQLException ex) {
- out.println("<p><b> Could not be registered due to a system error. </b></p><p>" + ex.getMessage()+ "</p>");
- stmt.close();
- conn.close();
- }
- %>
- <html>
- <body>
- <script>
- alert("Your profile has been successfully updated!");
- </script>
- </body>
- </html>
- <%
- response.setHeader("Refresh", "0;url=LoginPage.html");%>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement