SHARE
TWEET

Untitled

a guest May 22nd, 2017 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <%@ page contentType="text/html; charset=iso-8859-1" language="java"
  2. import="java.sql.*" errorPage="" %>
  3. <%
  4. PreparedStatement stmt = null;
  5. Connection conn = null;
  6. try {
  7. //Connect to the database
  8. Class.forName("oracle.jdbc.driver.OracleDriver");
  9. String hostname = "localhost";
  10. int port = 1521;
  11. String sid = "xe";
  12. String oracleURL = "jdbc:oracle:thin:@"+hostname+":"+port+":"+sid;
  13. String user = "system";
  14. String pass = "system";
  15. conn = DriverManager.getConnection(oracleURL, user, pass);
  16. %><script>alert("Your profile has been successfully updated!");</script><%
  17. //Create an empty new variable
  18. String message = null;
  19. String usertype = request.getParameter("usertype");
  20. String userid = session.getAttribute("userid");
  21. String username = request.getParameter("username");
  22. String password = request.getParameter("password");
  23. String usernamedb = "";
  24. String useriddb = "";
  25. if (usertype.equals("student")){
  26.     userid = "S"+userid;
  27.     usernamedb = "student_name";
  28.     useriddb = "student_id";
  29. }
  30. else{
  31.     userid = "T"+userid;
  32.     usernamedb = "teacher_name";
  33.     useriddb = "teacher_id";
  34. }
  35. // Make the query
  36.  
  37. stmt=conn.prepareStatement("update "+usertype+" set "+usernamedb+" = ?, password = ? where "+useriddb+" = ?");
  38. stmt.clearParameters();
  39. stmt.setString(1,username);
  40. stmt.setString(2,password);
  41. stmt.setString(3,userid);
  42.  
  43.  
  44. //Run the query
  45. stmt.executeUpdate();
  46. conn.commit();
  47.  
  48. out.println("<p> <b> You have been registered !</b></p>");
  49. //Close the database connection
  50. stmt.close();
  51. conn.close();
  52. } catch (SQLException ex) {
  53. out.println("<p><b> Could not be registered due to a system error. </b></p><p>" + ex.getMessage()+ "</p>");
  54. stmt.close();
  55. conn.close();
  56. }
  57. %>
  58. <html>
  59. <body>
  60. <script>
  61. alert("Your profile has been successfully updated!");
  62. </script>
  63. </body>
  64. </html>
  65. <%
  66. response.setHeader("Refresh", "0;url=LoginPage.html");%>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top