Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. @RequestMapping(value="helpgroups/helpsections/{id}" , method = RequestMethod.GET)
  2. public String listHgHelpSections(@ModelAttribute("helpSection") HelpSection helpSection, HelpGroup helpGroup,@PathVariable("id") Long id, BindingResult bindingResult)
  3. {
  4. helpGroup.setId(id);
  5. //info needed to connect to sql server
  6. final String dbUserName = "AAISdirectHelpUser";
  7. final String dbPassword = "Wr6Vaswa";
  8. final String dbURL = "jdbc:sqlserver://127.0.0.1;database=AAISdirectHelp";
  9.  
  10. // sql server connection
  11. try
  12. {
  13. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  14. Connection conn = DriverManager.getConnection(dbURL, dbUserName, dbPassword);
  15. String sql ="SELECT * FROM config.HelpSection WHERE HelpGroupID = ? ";
  16. PreparedStatement ps= conn.prepareStatement(sql);
  17. ps.setLong(1, helpGroup.getId());
  18. ResultSet results = ps.executeQuery();
  19. while(results.next())
  20. {
  21. helpSection = new HelpSection(results.getString("Name"), results.getLong("HelpSectionID"), results.getString("Description"), results.getLong("HelpGroupID"));
  22. helpGroup.getHelpSections().add(helpSection);
  23. }
  24. catch(SQLException e1)
  25. {
  26. e1.printStackTrace();
  27. }
  28. catch(ClassNotFoundException e2)
  29. {
  30. e2.printStackTrace();
  31. }
  32. catch(Exception e3)
  33. {
  34. e3.printStackTrace();
  35. }
  36.  
  37.  
  38. return "redirect:/helpgroups/helpsections/{id}";
  39.  
  40. }
  41.  
  42. //mapping to insert a new help section record
  43. @RequestMapping("/helpgroups/helpsections/{helpgroupid}/inserthelpsection")
  44. public String insertHelpSection(@ModelAttribute("helpSection") HelpSection helpSection,@PathVariable("helpgroupid") long helpGroupID, BindingResult bindingResult)
  45. {
  46.  
  47. final String dbUserName = "AAISdirectHelpUser";
  48. final String dbPassword = "Wr6Vaswa";
  49. final String dbURL = "jdbc:sqlserver://127.0.0.1;database=AAISdirectHelp";
  50. Connection conn = null;
  51.  
  52. try
  53. {
  54. Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  55. conn = DriverManager.getConnection(dbURL, dbUserName, dbPassword);
  56. String insertSQL ="INSERT INTO config.HelpSection (Name, Description, HelpGroupID,Sequence) VALUES (?,?,?,?)";
  57. PreparedStatement ps = conn.prepareStatement(insertSQL);
  58. ps.setString(1, helpSection.getName());
  59. ps.setString(2, helpSection.getDescription());
  60. ps.setLong(3, helpGroupID);
  61. ps.setLong(4, 0);
  62. ps.executeUpdate();
  63.  
  64. }
  65.  
  66. catch(SQLException e1)
  67. {
  68. e1.printStackTrace();
  69. }
  70. catch(ClassNotFoundException e2)
  71. {
  72. e2.printStackTrace();
  73. }
  74. catch(Exception e3)
  75. {
  76. e3.printStackTrace();
  77. }
  78.  
  79. return "redirect:/helpgroups/helpsections/{id}";
  80. }
  81.  
  82. package com.aais.helpguides;
  83.  
  84.  
  85. public class HelpSection
  86. {
  87. private long id;
  88. private long helpGroupID;
  89. private int sequence;
  90. private String name;
  91. private String description;
  92.  
  93.  
  94.  
  95. //default constructor
  96. public HelpSection()
  97. {
  98. }
  99.  
  100. //constructor with specific arguments
  101. public HelpSection(String name, long id, String description, long helpGroupID)
  102. {
  103. this.name = name;
  104. this.id = id;
  105. this.description = description;
  106. this.helpGroupID = helpGroupID;
  107. }
  108. public long getHelpGroupID()
  109. {
  110. return helpGroupID;
  111. }
  112. public void setHelpGroupID(long helpGroupID)
  113. {
  114. this.helpGroupID = helpGroupID;
  115. }
  116. public long getId()
  117. {
  118. return id;
  119. }
  120. public void setId(long id)
  121. {
  122. this.id = id;
  123. }
  124. public int getSequence()
  125. {
  126. return sequence;
  127. }
  128. public void setSequence(int sequence)
  129. {
  130. this.sequence = sequence;
  131. }
  132. public String getName()
  133. {
  134. return name;
  135. }
  136. public void setName(String name)
  137. {
  138. this.name = name;
  139. }
  140. public String getDescription()
  141. {
  142. return description;
  143. }
  144. public void setDescription(String description)
  145. {
  146. this.description = description;
  147. }
  148.  
  149.  
  150.  
  151. }
  152.  
  153. <!-- iterate over the arraylist -->
  154. <c:forEach var="section" items="${helpGroup.helpSections}">
  155. <tr>
  156. <td>${section.id}</td>
  157. <td><a href="helpsections/helpinfo/${section.id}">${section.name}</a></td>
  158. <td>${section.description}<td>
  159. </tr>
  160. </c:forEach>
  161. </table>
  162.  
  163. <hr>
  164. <h2>Insert Help Section</h2>
  165. <form:form method="post" action="${id}/inserthelpsection" modelAttribute="helpSection">
  166. <table style="width:750px">
  167. <tr>
  168. <td>Help Section Name:</td>
  169. <td><form:input type="text" path="name"/></td>
  170. <td>Description:</td>
  171. <td><form:input type="text" path="description" /></td>
  172. <%-- <td>Sequence:</td>
  173. <td><form:input type="text" path="sequence"/> --%>
  174. <td><input type="submit" value="Insert"/></td>
  175. </tr>
  176. </table>
  177. </form:form>
  178.  
  179. return new ModelAndView("newView", model);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement