Guest User

Untitled

a guest
Oct 17th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. <%@page import="java.sql.*" %>
  2. <%@page import="java.util.Date" %>
  3. <% Class.forName("com.mysql.jdbc.Driver"); %>
  4. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <title> My Mood Form</title>
  10. </head>
  11.  
  12.  
  13. <body>
  14.  
  15. <%!
  16. public class Actor {
  17. String URL = "jdbc:mysql://localhost/test";
  18. String USERNAME = "XXXXX";
  19. String PASSWORD = "XXXXX";
  20.  
  21. Connection connection = null;
  22. PreparedStatement insertActors = null;
  23. ResultSet resultSet = null;
  24.  
  25. public Actor () {
  26. try {
  27.  
  28. connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);
  29.  
  30. insertActors = connection.prepareStatement(
  31. "INSERT INTO mood(first_name, last_name, my_choice, last_update)"
  32. + " VALUES (?,?,?,?)");
  33.  
  34. } catch (SQLException e){
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39. public int setActors (String first, String last, String choice, Timestamp timeStamp){
  40. int result =0;
  41. try {
  42. insertActors.setString(1, first);
  43. insertActors.setString(2, last);
  44. insertActors.setString(3, choice);
  45. insertActors.setTimestamp(4, timeStamp);
  46. result = insertActors.executeUpdate();
  47. } catch (SQLException e) {
  48. e.printStackTrace();
  49. }
  50. return result;
  51. }
  52. }
  53. %>
  54.  
  55.  
  56. <%
  57. int result = 0;
  58. if (request.getParameter("submit") != null){
  59. String firstName = new String ();
  60. String lastName = new String ();
  61. String myChoice = new String ();
  62. //String [] myChoice;
  63.  
  64. if (request.getParameter("first") != null){
  65. firstName = request.getParameter("first");
  66. }
  67.  
  68. if (request.getParameter("last") != null){
  69. lastName = request.getParameter("last");
  70. }
  71.  
  72. if (request.getParameter("choice") != null){
  73. myChoice = request.getParameter("choice");
  74.  
  75.  
  76. /**
  77. * for (int i=0; i<selectedInterest.length; i++)
  78. {
  79. out.println(" " + selectedInterest[i] + "");
  80. s = s + selectedInterest[i] + ", ";
  81. out.println("s = " + s );
  82. }
  83. }
  84. else{
  85. out.println("none");
  86.  
  87. */
  88.  
  89. }
  90.  
  91. Date date = new Date();
  92. Timestamp timeStamp = new Timestamp (date.getTime());
  93.  
  94. Actor mood = new Actor();
  95. result = mood.setActors(firstName, lastName, myChoice, timeStamp);
  96. }
  97. %>
  98.  
  99. <h1>Registration Form</h1>
  100. <form name="Registration" action="index.jsp" method="POST">
  101. <table border="0" cellpadding="3">
  102. <tbody>
  103. <tr>
  104. <td>Surname:</td>
  105. <td><input type="text" name="first" size="40" /></td>
  106. </tr>
  107.  
  108. <tr>
  109. <td>First Name:</td>
  110. <td><input type="text" name="last" size="40" /></td>
  111. </tr>
  112.  
  113. <tr>
  114. <td>My Choice:</td>
  115. <td>
  116. <input type="checkbox" name="choice" value="excited" />I am excited<br>
  117. <input type="checkbox" name="choice" value="happy" />I am happy <br>
  118. <input type="checkbox" name="choice" value="indifference" />I am indifference<br>
  119. <input type="checkbox" name="choice" value="sad" />I am sad<br>
  120. </td>
  121. </tr>
  122.  
  123. <tr>
  124. <td><button type="reset" value="Reset">Reset</button></td>
  125. <td><button type="submit" value="submit" name="submit">Submit</button></td> </td>
  126. </tr>
  127. </tbody>
  128. </table>
  129. </form>
  130. </body>
Add Comment
Please, Sign In to add comment